Caijinglong il y a 6 ans
Parent
révision
5162f851d1

+ 5
- 6
example/lib/main.dart Voir le fichier

@@ -46,15 +46,17 @@ class MyHomePage extends StatefulWidget {
46 46
 class _MyHomePageState extends State<MyHomePage> {
47 47
   int _counter = 0;
48 48
 
49
-  void _incrementCounter() {
50
-    PhotoPicker.pickImage(
49
+  void _incrementCounter() async{
50
+    var imgList = await PhotoPicker.pickImage(
51 51
       context: context,
52 52
       themeColor: Colors.green,
53 53
       padding: 5.0,
54 54
       dividerColor: Colors.deepOrange,
55
-      disableColor: Colors.grey,
55
+      disableColor: Colors.grey.shade300,
56 56
       itemRadio: 0.88,
57 57
     );
58
+
59
+    print(imgList);
58 60
   }
59 61
 
60 62
   @override
@@ -108,7 +110,4 @@ class _MyHomePageState extends State<MyHomePage> {
108 110
     );
109 111
   }
110 112
 
111
-  void _test(){
112
-//    Navigator.of(context).pop
113
-  }
114 113
 }

+ 2
- 2
lib/photo.dart Voir le fichier

@@ -53,7 +53,7 @@ class PhotoPicker {
53 53
 
54 54
     themeColor ??= Theme.of(context)?.primaryColor ?? Colors.black;
55 55
     dividerColor ??= Theme.of(context)?.dividerColor ?? Colors.grey;
56
-    disableColor ??= Theme.of(context)?.dividerColor ?? Colors.grey;
56
+    disableColor ??= Theme.of(context)?.disabledColor ?? Colors.grey;
57 57
     textColor ??= Colors.white;
58 58
 
59 59
     var options = Options(
@@ -62,7 +62,7 @@ class PhotoPicker {
62 62
       maxSelected: maxSelected,
63 63
       itemRadio:itemRadio,
64 64
       padding: padding,
65
-      paddingColor: disableColor,
65
+      disableColor: disableColor,
66 66
       textColor: textColor,
67 67
       themeColor: themeColor,
68 68
     );

+ 3
- 6
lib/src/entity/options.dart Voir le fichier

@@ -15,7 +15,7 @@ class Options {
15 15
 
16 16
   final Color textColor;
17 17
 
18
-  final Color paddingColor;
18
+  final Color disableColor;
19 19
 
20 20
   const Options({
21 21
     this.rowCount,
@@ -25,11 +25,8 @@ class Options {
25 25
     this.themeColor,
26 26
     this.dividerColor,
27 27
     this.textColor,
28
-    this.paddingColor,
28
+    this.disableColor,
29 29
   });
30 30
 
31
-  @override
32
-  String toString() {
33
-    return 'Options{rowCount: $rowCount, maxSelected: $maxSelected, padding: $padding, themeColor: $themeColor, dividerColor: $dividerColor, textColor: $textColor, paddingColor: $paddingColor}';
34
-  }
31
+
35 32
 }

+ 62
- 31
lib/src/page/photo_main_page.dart Voir le fichier

@@ -54,32 +54,41 @@ class _PhotoMainPageState extends State<PhotoMainPage> with SelectedProvider {
54 54
       color: options.textColor,
55 55
       fontSize: 14.0,
56 56
     );
57
-    return DefaultTextStyle(
58
-      style: textStyle,
59
-      child: Scaffold(
60
-        appBar: AppBar(
61
-          backgroundColor: options.themeColor,
62
-          title: Text(
63
-            i18nProvider.getTitleText(options),
64
-          ),
65
-          actions: <Widget>[
66
-            FlatButton(
67
-              child: Text(
68
-                i18nProvider.getSureText(options, this),
69
-                style: textStyle,
70
-              ),
71
-              onPressed: sure,
57
+    return WillPopScope(
58
+      child: DefaultTextStyle(
59
+        style: textStyle,
60
+        child: Scaffold(
61
+          appBar: AppBar(
62
+            backgroundColor: options.themeColor,
63
+            title: Text(
64
+              i18nProvider.getTitleText(options),
72 65
             ),
73
-          ],
74
-        ),
75
-        body: _buildBody(),
76
-        bottomSheet: _BottomWidget(
77
-          provider: i18nProvider,
78
-          options: options,
79
-          onGalleryChange: _onGalleryChange,
80
-          selectedProvider: this,
66
+            actions: <Widget>[
67
+              FlatButton(
68
+                child: Text(
69
+                  i18nProvider.getSureText(options, this),
70
+                  style: selectedCount == 0
71
+                      ? textStyle.copyWith(color: options.disableColor)
72
+                      : textStyle,
73
+                ),
74
+                onPressed: selectedCount == 0 ? null : sure,
75
+              ),
76
+            ],
77
+          ),
78
+          body: _buildBody(),
79
+          bottomNavigationBar: _BottomWidget(
80
+            provider: i18nProvider,
81
+            options: options,
82
+            onGalleryChange: _onGalleryChange,
83
+            selectedProvider: this,
84
+          ),
81 85
         ),
82 86
       ),
87
+      onWillPop: () async {
88
+        selectedList.clear();
89
+        Navigator.of(context).pop(selectedList);
90
+        return false;
91
+      },
83 92
     );
84 93
   }
85 94
 
@@ -95,7 +104,7 @@ class _PhotoMainPageState extends State<PhotoMainPage> with SelectedProvider {
95 104
 
96 105
   Widget _buildBody() {
97 106
     return Container(
98
-      color: options.paddingColor,
107
+      color: options.disableColor,
99 108
       child: GridView.builder(
100 109
         gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
101 110
           crossAxisCount: options.rowCount,
@@ -206,7 +215,9 @@ class _PhotoMainPageState extends State<PhotoMainPage> with SelectedProvider {
206 215
     setState(() {});
207 216
   }
208 217
 
209
-  void sure() {}
218
+  void sure() {
219
+    Navigator.pop(context, selectedList);
220
+  }
210 221
 
211 222
   void _onItemClick(ImageEntity data) {}
212 223
 
@@ -244,15 +255,35 @@ class __BottomWidgetState extends State<_BottomWidget> {
244 255
 
245 256
   @override
246 257
   Widget build(BuildContext context) {
258
+    var textStyle = TextStyle(fontSize: 14.0, color: options.textColor);
259
+    print(MediaQuery.of(context).padding.bottom);
247 260
     return Container(
248 261
       color: options.themeColor,
249
-      height: 44.0,
250
-      child: Row(
251
-        children: <Widget>[
252
-          Text(
253
-            widget.galleryName,
262
+      child: SafeArea(
263
+        bottom: true,
264
+        child: Container(
265
+          height: 44.0,
266
+          child: Row(
267
+            children: <Widget>[
268
+              Text(
269
+                widget.galleryName,
270
+                style: textStyle,
271
+              ),
272
+              Expanded(
273
+                child: Container(),
274
+              ),
275
+              Container(
276
+                height: 44.0,
277
+                alignment: Alignment.center,
278
+                child: Text(
279
+                  i18nProvider.getPreviewText(options, widget.selectedProvider),
280
+                  style: textStyle,
281
+                ),
282
+                padding: const EdgeInsets.symmetric(horizontal: 8.0),
283
+              ),
284
+            ],
254 285
           ),
255
-        ],
286
+        ),
256 287
       ),
257 288
     );
258 289
   }

+ 12
- 0
lib/src/provider/i18n_provider.dart Voir le fichier

@@ -14,6 +14,8 @@ abstract class I18nProvider {
14 14
 
15 15
   String getMaxTipText(Options options);
16 16
 
17
+  String getAllGalleryText(Options options);
18
+
17 19
   I18NPermissionProvider getNotPermissionText(Options options);
18 20
 
19 21
   static const I18nProvider chinese = _CNProvider();
@@ -49,6 +51,11 @@ class _CNProvider extends I18nProvider {
49 51
     return "您已经选择了${options.maxSelected}张图片";
50 52
   }
51 53
 
54
+  @override
55
+  String getAllGalleryText(Options options) {
56
+    return "全部图片";
57
+  }
58
+
52 59
   @override
53 60
   I18NPermissionProvider getNotPermissionText(Options options) {
54 61
     return I18NPermissionProvider(
@@ -84,6 +91,11 @@ class _ENProvider extends I18nProvider {
84 91
     return "select ${options.maxSelected} pictures at most";
85 92
   }
86 93
 
94
+  @override
95
+  String getAllGalleryText(Options options) {
96
+    return "all images";
97
+  }
98
+
87 99
   @override
88 100
   I18NPermissionProvider getNotPermissionText(Options options) {
89 101
     return I18NPermissionProvider(