Browse Source

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

cjl_macbook 6 years ago
parent
commit
ccc50c96e2

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

@@ -38,7 +38,7 @@ class _MyHomePageState extends State<MyHomePage> {
38 38
       itemRadio: 0.88,
39 39
     );
40 40
 
41
-    print(imgList);
41
+    print("imgList = $imgList");
42 42
   }
43 43
 
44 44
   @override

+ 5
- 5
lib/photo.dart View File

@@ -19,7 +19,7 @@ class PhotoPicker {
19 19
     return _instance;
20 20
   }
21 21
 
22
-  
22
+  static const String rootRouteName = "photo_picker_image";
23 23
 
24 24
   /// 没有授予权限的时候,会开启一个dialog去帮助用户去应用设置页面开启权限
25 25
   /// 确定开启设置页面,取消关闭弹窗
@@ -96,13 +96,13 @@ class PhotoPicker {
96 96
   }
97 97
 
98 98
   Future<List<ImageEntity>> _openGalleryContentPage(
99
-      BuildContext context, Options options, I18nProvider provider) {
99
+      BuildContext context, Options options, I18nProvider provider)async{
100 100
     return Navigator.of(context).push(
101 101
       MaterialPageRoute(
102 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,7 +6,7 @@ abstract class I18nProvider {
6 6
 
7 7
   String getTitleText(Options options);
8 8
 
9
-  String getSureText(Options options, SelectedProvider selectedProvider);
9
+  String getSureText(Options options, int currentCount);
10 10
 
11 11
   String getPreviewText(Options options, SelectedProvider selectedProvider);
12 12
 
@@ -37,8 +37,8 @@ class _CNProvider extends I18nProvider {
37 37
   }
38 38
 
39 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 44
   @override
@@ -77,8 +77,8 @@ class _ENProvider extends I18nProvider {
77 77
   }
78 78
 
79 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 84
   @override

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

@@ -87,7 +87,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
87 87
             actions: <Widget>[
88 88
               FlatButton(
89 89
                 child: Text(
90
-                  i18nProvider.getSureText(options, this),
90
+                  i18nProvider.getSureText(options, selectedCount),
91 91
                   style: selectedCount == 0
92 92
                       ? textStyle.copyWith(color: options.disableColor)
93 93
                       : textStyle,
@@ -290,6 +290,10 @@ class _PhotoMainPageState extends State<PhotoMainPage>
290 290
         },
291 291
       ),
292 292
     ).then((v) {
293
+      if (handlePreviewResult(v)) {
294
+        Navigator.pop(context, v);
295
+        return;
296
+      }
293 297
       isPushed = false;
294 298
       setState(() {});
295 299
     });
@@ -315,11 +319,26 @@ class _PhotoMainPageState extends State<PhotoMainPage>
315 319
     )
316 320
         .then(
317 321
       (v) {
322
+        if (handlePreviewResult(v)) {
323
+          print(v);
324
+          Navigator.pop(context, v);
325
+          return;
326
+        }
318 327
         isPushed = false;
319 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 344
 class _BottomWidget extends StatefulWidget {

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

@@ -96,6 +96,10 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
96 96
 
97 97
   @override
98 98
   Widget build(BuildContext context) {
99
+    var textStyle = TextStyle(
100
+      color: options.textColor,
101
+      fontSize: 14.0,
102
+    );
99 103
     return Theme(
100 104
       data: Theme.of(context).copyWith(primaryColor: options.themeColor),
101 105
       child: Scaffold(
@@ -108,6 +112,20 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
108 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 130
         body: PageView.builder(
113 131
           controller: pageController,
@@ -250,6 +268,10 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
250 268
     var itemIndex = list.indexOf(entity);
251 269
     if (itemIndex != -1) pageController.jumpToPage(itemIndex);
252 270
   }
271
+
272
+  void sure() {
273
+    Navigator.pop(context, selectedList);
274
+  }
253 275
 }
254 276
 
255 277
 class BigPhotoImage extends StatefulWidget {