瀏覽代碼

Remove unnecessary injected field

Vishnu 4 年之前
父節點
當前提交
dadce38ef3
共有 2 個文件被更改,包括 23 次插入16 次删除
  1. 1 7
      lib/ui/fading_bottom_bar.dart
  2. 22 9
      lib/ui/file_info_dialog.dart

+ 1 - 7
lib/ui/fading_bottom_bar.dart

@@ -2,7 +2,6 @@ import 'dart:io';
 
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
-import 'package:photo_manager/photo_manager.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/ui/file_info_dialog.dart';
@@ -111,15 +110,10 @@ class FadingBottomBarState extends State<FadingBottomBar> {
   }
 
   Future<void> _displayInfo(File file) async {
-    AssetEntity asset;
-    final isLocalFile = file.localID != null;
-    if (isLocalFile) {
-      asset = await file.getAsset();
-    }
     return showDialog<void>(
       context: context,
       builder: (BuildContext context) {
-        return FileInfoWidget(file, asset);
+        return FileInfoWidget(file);
       },
     );
   }

+ 22 - 9
lib/ui/file_info_dialog.dart

@@ -1,7 +1,6 @@
 import 'package:exif/exif.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
-import 'package:photo_manager/photo_manager.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/services/collections_service.dart';
@@ -11,11 +10,9 @@ import 'package:photos/utils/file_util.dart';
 
 class FileInfoWidget extends StatelessWidget {
   final File file;
-  final AssetEntity entity;
 
   const FileInfoWidget(
-    this.file,
-    this.entity, {
+    this.file, {
     Key key,
   }) : super(key: key);
 
@@ -86,11 +83,27 @@ class FileInfoWidget extends StatelessWidget {
                 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),
-                ),
+              FutureBuilder(
+                future: file.getAsset(),
+                builder: (context, snapshot) {
+                  if (snapshot.hasData) {
+                    return Text(
+                      snapshot.data.videoDuration.toString().split(".")[0],
+                      style: TextStyle(
+                        color: Colors.white.withOpacity(0.85),
+                      ),
+                    );
+                  } else {
+                    return Center(
+                      child: SizedBox.fromSize(
+                        size: Size.square(24),
+                        child: CupertinoActivityIndicator(
+                          radius: 8,
+                        ),
+                      ),
+                    );
+                  }
+                },
               ),
             ],
           ),