From c08467555214999d1a7d8e7e21c7907922fcfd70 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 13 Mar 2023 17:47:57 +0530 Subject: [PATCH] Refactored FilePropertiesItemWidget --- .../file_properties_item_widget.dart | 114 +++++++----------- 1 file changed, 46 insertions(+), 68 deletions(-) diff --git a/lib/ui/viewer/file_details/file_properties_item_widget.dart b/lib/ui/viewer/file_details/file_properties_item_widget.dart index 1698db5c6..11537fbbc 100644 --- a/lib/ui/viewer/file_details/file_properties_item_widget.dart +++ b/lib/ui/viewer/file_details/file_properties_item_widget.dart @@ -1,11 +1,8 @@ -import "package:flutter/cupertino.dart"; import "package:flutter/material.dart"; import 'package:path/path.dart' as path; -import "package:photo_manager/photo_manager.dart"; import "package:photos/models/file.dart"; import "package:photos/models/file_type.dart"; import "package:photos/theme/ente_theme.dart"; -import "package:photos/ui/common/loading_widget.dart"; import "package:photos/ui/components/info_item_widget.dart"; import "package:photos/utils/date_time_util.dart"; import "package:photos/utils/file_util.dart"; @@ -30,8 +27,6 @@ class FilePropertiesWidget extends StatefulWidget { class _FilePropertiesWidgetState extends State { @override Widget build(BuildContext context) { - final bool showDimension = widget.exifData["resolution"] != null && - widget.exifData["megaPixels"] != null; return InfoItemWidget( key: const ValueKey("File properties"), leadingIcon: widget.isImage @@ -39,18 +34,7 @@ class _FilePropertiesWidgetState extends State { : Icons.video_camera_back_outlined, title: path.basenameWithoutExtension(widget.file.displayName) + path.extension(widget.file.displayName).toUpperCase(), - subtitleSection: Future.value([ - if (showDimension) - Text( - "${widget.exifData["megaPixels"]}MP " - "${widget.exifData["resolution"]} ", - style: getEnteTextTheme(context).smallMuted, - ), - _getFileSize(), - if ((widget.file.fileType == FileType.video) && - (widget.file.localID != null || widget.file.duration != 0)) - _getVideoDuration(), - ]), + subtitleSection: _subTitleSection(), editOnTap: widget.file.uploadedFileID == null || widget.file.ownerID != widget.currentUserID ? null @@ -61,60 +45,54 @@ class _FilePropertiesWidgetState extends State { ); } - Widget _getFileSize() { - Future fileSizeFuture; - if (widget.file.fileSize != null) { - fileSizeFuture = Future.value(widget.file.fileSize); - } else { - fileSizeFuture = getFile(widget.file).then((f) => f!.length()); - } - return FutureBuilder( - future: fileSizeFuture, - builder: (context, snapshot) { - if (snapshot.hasData) { - return Text( - (snapshot.data! / (1024 * 1024)).toStringAsFixed(2) + " MB", - style: getEnteTextTheme(context).smallMuted, - ); - } else { - return SizedBox.fromSize( - size: const Size.square(16), - child: EnteLoadingWidget( - padding: 3, - color: getEnteColorScheme(context).strokeMuted, - ), - ); - } - }, - ); - } + Future> _subTitleSection() async { + final bool showDimension = widget.exifData["resolution"] != null && + widget.exifData["megaPixels"] != null; + final subSectionWidgets = []; - Widget _getVideoDuration() { - if (widget.file.duration != 0) { - return Text( - secondsToHHMMSS(widget.file.duration!), - style: getEnteTextTheme(context).smallMuted, + if (showDimension) { + subSectionWidgets.add( + Text( + "${widget.exifData["megaPixels"]}MP " + "${widget.exifData["resolution"]} ", + style: getEnteTextTheme(context).smallMuted, + ), ); } - return FutureBuilder( - future: widget.file.getAsset, - builder: (context, snapshot) { - if (snapshot.hasData) { - return Text( - snapshot.data!.videoDuration.toString().split(".")[0], - style: getEnteTextTheme(context).smallMuted, - ); - } else { - return Center( - child: SizedBox.fromSize( - size: const Size.square(24), - child: const CupertinoActivityIndicator( - radius: 8, - ), - ), - ); - } - }, + + int fileSize; + if (widget.file.fileSize != null) { + fileSize = widget.file.fileSize!; + } else { + fileSize = await getFile(widget.file).then((f) => f!.length()); + } + subSectionWidgets.add( + Text( + (fileSize / (1024 * 1024)).toStringAsFixed(2) + " MB", + style: getEnteTextTheme(context).smallMuted, + ), ); + + if ((widget.file.fileType == FileType.video) && + (widget.file.localID != null || widget.file.duration != 0)) { + if (widget.file.duration != 0) { + subSectionWidgets.add( + Text( + secondsToHHMMSS(widget.file.duration!), + style: getEnteTextTheme(context).smallMuted, + ), + ); + } else { + final asset = await widget.file.getAsset; + subSectionWidgets.add( + Text( + asset!.videoDuration.toString().split(".")[0], + style: getEnteTextTheme(context).smallMuted, + ), + ); + } + } + + return Future.value(subSectionWidgets); } }