Prechádzať zdrojové kódy

Display sizes for remote files too

Vishnu 4 rokov pred
rodič
commit
4c05226e68
2 zmenil súbory, kde vykonal 45 pridanie a 31 odobranie
  1. 1 3
      lib/ui/fading_bottom_bar.dart
  2. 44 28
      lib/ui/file_info_dialog.dart

+ 1 - 3
lib/ui/fading_bottom_bar.dart

@@ -112,16 +112,14 @@ class FadingBottomBarState extends State<FadingBottomBar> {
 
   Future<void> _displayInfo(File file) async {
     AssetEntity asset;
-    int fileSize;
     final isLocalFile = file.localID != null;
     if (isLocalFile) {
       asset = await file.getAsset();
-      fileSize = await (await asset.originFile).length();
     }
     return showDialog<void>(
       context: context,
       builder: (BuildContext context) {
-        return FileInfoWidget(file, asset, fileSize);
+        return FileInfoWidget(file, asset);
       },
     );
   }

+ 44 - 28
lib/ui/file_info_dialog.dart

@@ -12,12 +12,10 @@ import 'package:photos/utils/file_util.dart';
 class FileInfoWidget extends StatelessWidget {
   final File file;
   final AssetEntity entity;
-  final int fileSize;
 
   const FileInfoWidget(
     this.file,
-    this.entity,
-    this.fileSize, {
+    this.entity, {
     Key key,
   }) : super(key: key);
 
@@ -63,18 +61,33 @@ class FileInfoWidget extends StatelessWidget {
       ),
       Padding(padding: EdgeInsets.all(6)),
     ];
-    if (file.localID != null) {
+    items.addAll(
+      [
+        Row(
+          children: [
+            Icon(
+              Icons.sd_storage_outlined,
+              color: Colors.white.withOpacity(0.85),
+            ),
+            Padding(padding: EdgeInsets.all(4)),
+            _getFileSize(),
+          ],
+        ),
+        Padding(padding: EdgeInsets.all(6)),
+      ],
+    );
+    if (file.localID != null && !isImage) {
       items.addAll(
         [
           Row(
             children: [
               Icon(
-                Icons.sd_storage_outlined,
+                Icons.timer_outlined,
                 color: Colors.white.withOpacity(0.85),
               ),
               Padding(padding: EdgeInsets.all(4)),
               Text(
-                (fileSize / (1024 * 1024)).toStringAsFixed(2) + " MB",
+                entity.videoDuration.toString().split(".")[0],
                 style: TextStyle(
                   color: Colors.white.withOpacity(0.85),
                 ),
@@ -84,28 +97,6 @@ class FileInfoWidget extends StatelessWidget {
           Padding(padding: EdgeInsets.all(6)),
         ],
       );
-      if (!isImage) {
-        items.addAll(
-          [
-            Row(
-              children: [
-                Icon(
-                  Icons.timer_outlined,
-                  color: Colors.white.withOpacity(0.85),
-                ),
-                Padding(padding: EdgeInsets.all(4)),
-                Text(
-                  entity.videoDuration.toString().split(".")[0],
-                  style: TextStyle(
-                    color: Colors.white.withOpacity(0.85),
-                  ),
-                ),
-              ],
-            ),
-            Padding(padding: EdgeInsets.all(6)),
-          ],
-        );
-      }
     }
     if (isImage) {
       items.add(
@@ -350,6 +341,31 @@ class FileInfoWidget extends StatelessWidget {
     );
   }
 
+  Widget _getFileSize() {
+    return FutureBuilder(
+      future: getFile(file).then((f) => f.lengthSync()),
+      builder: (context, snapshot) {
+        if (snapshot.hasData) {
+          return Text(
+            (snapshot.data / (1024 * 1024)).toStringAsFixed(2) + " MB",
+            style: TextStyle(
+              color: Colors.white.withOpacity(0.85),
+            ),
+          );
+        } else {
+          return Center(
+            child: SizedBox.fromSize(
+              size: Size.square(24),
+              child: CupertinoActivityIndicator(
+                radius: 8,
+              ),
+            ),
+          );
+        }
+      },
+    );
+  }
+
   Future<Map<String, IfdTag>> _getExif() async {
     return await readExifFromFile(await getFile(file));
   }