Browse Source

增加了给预览页面增加了确定按钮

cjl_macbook 6 years ago
parent
commit
ccc50c96e2

+ 1
- 1
example/lib/main.dart View File

38
       itemRadio: 0.88,
38
       itemRadio: 0.88,
39
     );
39
     );
40
 
40
 
41
-    print(imgList);
41
+    print("imgList = $imgList");
42
   }
42
   }
43
 
43
 
44
   @override
44
   @override

+ 5
- 5
lib/photo.dart View File

19
     return _instance;
19
     return _instance;
20
   }
20
   }
21
 
21
 
22
-  
22
+  static const String rootRouteName = "photo_picker_image";
23
 
23
 
24
   /// 没有授予权限的时候,会开启一个dialog去帮助用户去应用设置页面开启权限
24
   /// 没有授予权限的时候,会开启一个dialog去帮助用户去应用设置页面开启权限
25
   /// 确定开启设置页面,取消关闭弹窗
25
   /// 确定开启设置页面,取消关闭弹窗
96
   }
96
   }
97
 
97
 
98
   Future<List<ImageEntity>> _openGalleryContentPage(
98
   Future<List<ImageEntity>> _openGalleryContentPage(
99
-      BuildContext context, Options options, I18nProvider provider) {
99
+      BuildContext context, Options options, I18nProvider provider)async{
100
     return Navigator.of(context).push(
100
     return Navigator.of(context).push(
101
       MaterialPageRoute(
101
       MaterialPageRoute(
102
         builder: (ctx) => PhotoApp(
102
         builder: (ctx) => PhotoApp(
103
-              options: options,
104
-              provider: provider,
105
-            ),
103
+          options: options,
104
+          provider: provider,
105
+        ),
106
       ),
106
       ),
107
     );
107
     );
108
   }
108
   }

+ 5
- 5
lib/src/provider/i18n_provider.dart View File

6
 
6
 
7
   String getTitleText(Options options);
7
   String getTitleText(Options options);
8
 
8
 
9
-  String getSureText(Options options, SelectedProvider selectedProvider);
9
+  String getSureText(Options options, int currentCount);
10
 
10
 
11
   String getPreviewText(Options options, SelectedProvider selectedProvider);
11
   String getPreviewText(Options options, SelectedProvider selectedProvider);
12
 
12
 
37
   }
37
   }
38
 
38
 
39
   @override
39
   @override
40
-  String getSureText(Options options, SelectedProvider selectedProvider) {
41
-    return "确定(${selectedProvider.selectedCount}/${options.maxSelected})";
40
+  String getSureText(Options options, int currentCount) {
41
+    return "确定($currentCount/${options.maxSelected})";
42
   }
42
   }
43
 
43
 
44
   @override
44
   @override
77
   }
77
   }
78
 
78
 
79
   @override
79
   @override
80
-  String getSureText(Options options, SelectedProvider selectedProvider) {
81
-    return "sure(${selectedProvider.selectedCount}/${options.maxSelected})";
80
+  String getSureText(Options options, int currentCount) {
81
+    return "sure($currentCount/${options.maxSelected})";
82
   }
82
   }
83
 
83
 
84
   @override
84
   @override

+ 20
- 1
lib/src/ui/page/photo_main_page.dart View File

87
             actions: <Widget>[
87
             actions: <Widget>[
88
               FlatButton(
88
               FlatButton(
89
                 child: Text(
89
                 child: Text(
90
-                  i18nProvider.getSureText(options, this),
90
+                  i18nProvider.getSureText(options, selectedCount),
91
                   style: selectedCount == 0
91
                   style: selectedCount == 0
92
                       ? textStyle.copyWith(color: options.disableColor)
92
                       ? textStyle.copyWith(color: options.disableColor)
93
                       : textStyle,
93
                       : textStyle,
290
         },
290
         },
291
       ),
291
       ),
292
     ).then((v) {
292
     ).then((v) {
293
+      if (handlePreviewResult(v)) {
294
+        Navigator.pop(context, v);
295
+        return;
296
+      }
293
       isPushed = false;
297
       isPushed = false;
294
       setState(() {});
298
       setState(() {});
295
     });
299
     });
315
     )
319
     )
316
         .then(
320
         .then(
317
       (v) {
321
       (v) {
322
+        if (handlePreviewResult(v)) {
323
+          print(v);
324
+          Navigator.pop(context, v);
325
+          return;
326
+        }
318
         isPushed = false;
327
         isPushed = false;
319
         compareAndRemoveEntities(result.previewSelectedList);
328
         compareAndRemoveEntities(result.previewSelectedList);
320
       },
329
       },
321
     );
330
     );
322
   }
331
   }
332
+
333
+  bool handlePreviewResult(List<ImageEntity> v) {
334
+    if (v == null) {
335
+      return false;
336
+    }
337
+    if (v is List<ImageEntity>) {
338
+      return true;
339
+    }
340
+    return false;
341
+  }
323
 }
342
 }
324
 
343
 
325
 class _BottomWidget extends StatefulWidget {
344
 class _BottomWidget extends StatefulWidget {

+ 22
- 0
lib/src/ui/page/photo_preview_page.dart View File

96
 
96
 
97
   @override
97
   @override
98
   Widget build(BuildContext context) {
98
   Widget build(BuildContext context) {
99
+    var textStyle = TextStyle(
100
+      color: options.textColor,
101
+      fontSize: 14.0,
102
+    );
99
     return Theme(
103
     return Theme(
100
       data: Theme.of(context).copyWith(primaryColor: options.themeColor),
104
       data: Theme.of(context).copyWith(primaryColor: options.themeColor),
101
       child: Scaffold(
105
       child: Scaffold(
108
                   "${snap.data + 1}/${widget.list.length}",
112
                   "${snap.data + 1}/${widget.list.length}",
109
                 ),
113
                 ),
110
           ),
114
           ),
115
+          actions: <Widget>[
116
+            FlatButton(
117
+              child: StreamBuilder(
118
+                stream: pageStream,
119
+                builder: (ctx, s) => Text(
120
+                      config.provider.getSureText(options, selectedList.length),
121
+                      style: selectedList.length == 0
122
+                          ? textStyle.copyWith(color: options.disableColor)
123
+                          : textStyle,
124
+                    ),
125
+              ),
126
+              onPressed: selectedList.length == 0 ? null : sure,
127
+            ),
128
+          ],
111
         ),
129
         ),
112
         body: PageView.builder(
130
         body: PageView.builder(
113
           controller: pageController,
131
           controller: pageController,
250
     var itemIndex = list.indexOf(entity);
268
     var itemIndex = list.indexOf(entity);
251
     if (itemIndex != -1) pageController.jumpToPage(itemIndex);
269
     if (itemIndex != -1) pageController.jumpToPage(itemIndex);
252
   }
270
   }
271
+
272
+  void sure() {
273
+    Navigator.pop(context, selectedList);
274
+  }
253
 }
275
 }
254
 
276
 
255
 class BigPhotoImage extends StatefulWidget {
277
 class BigPhotoImage extends StatefulWidget {