Browse Source

fix is_full radio

lucky1213 4 years ago
parent
commit
ba5d1c84fb

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

120
                 text: "Picked asset example.",
120
                 text: "Picked asset example.",
121
                 onTap: () => routePage(PickedExample()),
121
                 onTap: () => routePage(PickedExample()),
122
               ),
122
               ),
123
-              Container(
124
-                height: 210,
125
-                child: PhotoPicker.buildGallery(
126
-                  context: context,
127
-                  padding: 4.0,
128
-                  itemHeight: 210,
129
-                  itemWidth: 180,
130
-                  provider: I18nProvider.chinese,
131
-                  sortDelegate: SortDelegate.common,
132
-                  loadingDelegate: this,
133
-                  pickType: PickType.onlyImage,
134
-                  photoPathList: null,
135
-                  onSelected: (List<AssetEntity> value) {
136
-                    print(value);
137
-                  }
138
-                ),
139
-              )
123
+              // Container(
124
+              //   height: 210,
125
+              //   child: PhotoPicker.buildGallery(
126
+              //     context: context,
127
+              //     padding: 4.0,
128
+              //     itemHeight: 210,
129
+              //     itemWidth: 180,
130
+              //     provider: I18nProvider.chinese,
131
+              //     sortDelegate: SortDelegate.common,
132
+              //     loadingDelegate: this,
133
+              //     pickType: PickType.onlyImage,
134
+              //     photoPathList: null,
135
+              //     onSelected: (List<AssetEntity> value) {
136
+              //       print(value);
137
+              //     }
138
+              //   ),
139
+              // )
140
             ],
140
             ],
141
           ),
141
           ),
142
         ),
142
         ),

+ 10
- 6
lib/photo.dart View File

24
 export 'package:photo/src/delegate/sort_delegate.dart';
24
 export 'package:photo/src/delegate/sort_delegate.dart';
25
 export 'package:photo/src/provider/i18n_provider.dart'
25
 export 'package:photo/src/provider/i18n_provider.dart'
26
     show I18NCustomProvider, I18nProvider, CNProvider, ENProvider;
26
     show I18NCustomProvider, I18nProvider, CNProvider, ENProvider;
27
-export 'package:photo/src/entity/options.dart' show PickType;
27
+export 'package:photo/src/entity/options.dart' show PickType, PickedEntity;
28
 export 'package:photo/src/delegate/badge_delegate.dart';
28
 export 'package:photo/src/delegate/badge_delegate.dart';
29
 export 'package:photo/src/entity/_theme.dart';
29
 export 'package:photo/src/entity/_theme.dart';
30
 
30
 
70
   ///   [pickedAssetList]: The results of the last selection can be passed in for easy secondary selection.
70
   ///   [pickedAssetList]: The results of the last selection can be passed in for easy secondary selection.
71
   ///
71
   ///
72
   /// params see readme.md
72
   /// params see readme.md
73
-  static Future<List<AssetEntity>> pickAsset({
73
+  static Future<PickedEntity> pickAsset({
74
     @required BuildContext context,
74
     @required BuildContext context,
75
     int rowCount = 4,
75
     int rowCount = 4,
76
     int maxSelected = 9,
76
     int maxSelected = 9,
116
     );
116
     );
117
   }
117
   }
118
 
118
 
119
-  Future<List<AssetEntity>> _pickAsset(
119
+  Future<PickedEntity> _pickAsset(
120
     BuildContext context,
120
     BuildContext context,
121
     Options options,
121
     Options options,
122
     I18nProvider provider,
122
     I18nProvider provider,
137
   static Widget buildGallery({
137
   static Widget buildGallery({
138
     @required BuildContext context,
138
     @required BuildContext context,
139
     double padding = 1,
139
     double padding = 1,
140
+    int maxSelected = 9,
140
     int thumbSize = 180,
141
     int thumbSize = 180,
141
     double itemRadio = 1.0,
142
     double itemRadio = 1.0,
142
     PhotoTheme theme,
143
     PhotoTheme theme,
146
     PickType pickType = PickType.all,
147
     PickType pickType = PickType.all,
147
     List<AssetPathEntity> photoPathList,
148
     List<AssetPathEntity> photoPathList,
148
     List<AssetEntity> pickedAssetList,
149
     List<AssetEntity> pickedAssetList,
149
-    void Function(List<AssetEntity> value) onSelected,
150
+    bool isFullImage = false,
151
+    void Function(PickedEntity value) onSelected,
150
   }) {
152
   }) {
151
     sortDelegate ??= SortDelegate.common;
153
     sortDelegate ??= SortDelegate.common;
152
 
154
 
154
 
156
 
155
     var options = ListOptions(
157
     var options = ListOptions(
156
       padding: padding,
158
       padding: padding,
159
+      maxSelected: maxSelected,
157
       itemRadio: itemRadio,
160
       itemRadio: itemRadio,
158
       theme: theme ?? PhotoTheme.fallback(context),
161
       theme: theme ?? PhotoTheme.fallback(context),
159
       thumbSize: thumbSize,
162
       thumbSize: thumbSize,
176
       child: PhotoListPage(
179
       child: PhotoListPage(
177
         onSelected: onSelected,
180
         onSelected: onSelected,
178
         options: options,
181
         options: options,
182
+        isFullImage: isFullImage,
179
       ),
183
       ),
180
     );
184
     );
181
   }
185
   }
196
     }
200
     }
197
   }
201
   }
198
 
202
 
199
-  Future<List<AssetEntity>> _openGalleryContentPage(
203
+  Future<PickedEntity> _openGalleryContentPage(
200
     BuildContext context,
204
     BuildContext context,
201
     Options options,
205
     Options options,
202
     I18nProvider provider,
206
     I18nProvider provider,
212
             pickedAssetList: pickedAssetList,
216
             pickedAssetList: pickedAssetList,
213
           ),
217
           ),
214
           child: PhotoMainPage(
218
           child: PhotoMainPage(
215
-            onClose: (List<AssetEntity> value) {
219
+            onClose: (PickedEntity value) {
216
               Navigator.pop(ctx, value);
220
               Navigator.pop(ctx, value);
217
             },
221
             },
218
             options: options,
222
             options: options,

+ 7
- 0
lib/src/entity/options.dart View File

4
 import 'package:photo/src/delegate/loading_delegate.dart';
4
 import 'package:photo/src/delegate/loading_delegate.dart';
5
 import 'package:photo/src/delegate/sort_delegate.dart';
5
 import 'package:photo/src/delegate/sort_delegate.dart';
6
 import 'package:photo/src/entity/_theme.dart';
6
 import 'package:photo/src/entity/_theme.dart';
7
+import 'package:photo_manager/photo_manager.dart';
7
 
8
 
8
 class Options {
9
 class Options {
9
   final int rowCount;
10
   final int rowCount;
78
   onlyImage,
79
   onlyImage,
79
   onlyVideo,
80
   onlyVideo,
80
 }
81
 }
82
+
83
+class PickedEntity {
84
+  const PickedEntity({List<AssetEntity> asset, this.isFullImage = false}) : asset = asset ?? const[];
85
+  final List<AssetEntity> asset;
86
+  final bool isFullImage;
87
+}

+ 10
- 4
lib/src/provider/config_provider.dart View File

7
 // ignore_for_file: deprecated_member_use
7
 // ignore_for_file: deprecated_member_use
8
 
8
 
9
 class PhotoProvider extends ChangeNotifier {
9
 class PhotoProvider extends ChangeNotifier {
10
-  final Options options;
11
-  final I18nProvider provider;
12
-  final AssetProvider assetProvider = AssetProvider();
13
-  final List<AssetEntity> pickedAssetList;
10
+  Options options;
11
+  I18nProvider provider;
12
+  AssetProvider assetProvider = AssetProvider();
13
+  List<AssetEntity> pickedAssetList;
14
+  bool isFullImage;
14
   PhotoProvider({
15
   PhotoProvider({
15
     @required this.options,
16
     @required this.options,
16
     @required this.provider,
17
     @required this.provider,
17
     List<AssetEntity> pickedAssetList,
18
     List<AssetEntity> pickedAssetList,
19
+    this.isFullImage = false,
18
   }) : this.pickedAssetList = pickedAssetList ?? [];
20
   }) : this.pickedAssetList = pickedAssetList ?? [];
19
   
21
   
22
+  void setFullImage(bool value) {
23
+    isFullImage = value;
24
+    notifyListeners();
25
+  }
20
 
26
 
21
   @override
27
   @override
22
   void notifyListeners() {
28
   void notifyListeners() {

+ 20
- 13
lib/src/ui/page/photo_list_page.dart View File

12
 import 'photo_preview_page.dart';
12
 import 'photo_preview_page.dart';
13
 
13
 
14
 class PhotoListPage extends StatefulWidget {
14
 class PhotoListPage extends StatefulWidget {
15
-  final ValueChanged<List<AssetEntity>> onSelected;
15
+  final ValueChanged<PickedEntity> onSelected;
16
   final ListOptions options;
16
   final ListOptions options;
17
+  final bool isFullImage;
17
 
18
 
18
   const PhotoListPage({
19
   const PhotoListPage({
19
     Key key,
20
     Key key,
20
     this.onSelected,
21
     this.onSelected,
21
     this.options,
22
     this.options,
23
+    this.isFullImage = false,
22
   }) : super(key: key);
24
   }) : super(key: key);
23
 
25
 
24
   @override
26
   @override
27
 
29
 
28
 class _PhotoListPageState extends State<PhotoListPage>
30
 class _PhotoListPageState extends State<PhotoListPage>
29
     with SelectedProvider, GalleryListProvider, WidgetsBindingObserver {
31
     with SelectedProvider, GalleryListProvider, WidgetsBindingObserver {
30
-  PhotoProvider get config =>
31
-      Provider.of<PhotoProvider>(context, listen: false);
32
+  PhotoProvider get config => Provider.of<PhotoProvider>(context, listen: false);
32
   ListOptions get options => widget.options;
33
   ListOptions get options => widget.options;
33
   I18nProvider get i18nProvider => config.provider;
34
   I18nProvider get i18nProvider => config.provider;
34
   AssetProvider get assetProvider => config.assetProvider;
35
   AssetProvider get assetProvider => config.assetProvider;
63
       //   return null;
64
       //   return null;
64
       // }
65
       // }
65
       if (!_isInit) {
66
       if (!_isInit) {
67
+        
66
         final pickedList = config.pickedAssetList ?? [];
68
         final pickedList = config.pickedAssetList ?? [];
67
         addPickedAsset(pickedList.toList());
69
         addPickedAsset(pickedList.toList());
68
         _refreshList();
70
         _refreshList();
141
 
143
 
142
   @override
144
   @override
143
   void sure() {
145
   void sure() {
144
-    widget.onSelected?.call(selectedList);
146
+    widget.onSelected?.call(PickedEntity(
147
+      asset: selectedList,
148
+      isFullImage: isFullImage,
149
+    ));
145
   }
150
   }
146
 
151
 
147
   void _showTip(String msg) {
152
   void _showTip(String msg) {
163
 
168
 
164
   @override
169
   @override
165
   Widget build(BuildContext context) {
170
   Widget build(BuildContext context) {
171
+    isFullImage = widget.isFullImage;
166
     if (!_isInit) {
172
     if (!_isInit) {
167
       return Container();
173
       return Container();
168
       // return _buildLoading();
174
       // return _buildLoading();
289
 
295
 
290
   void _onItemClick(AssetEntity data, int index) {
296
   void _onItemClick(AssetEntity data, int index) {
291
     var result = PhotoPreviewResult();
297
     var result = PhotoPreviewResult();
292
-    isPushed = true;
298
+    // isPushed = true;
293
     Navigator.of(context).push(
299
     Navigator.of(context).push(
294
       MaterialPageRoute(
300
       MaterialPageRoute(
295
         builder: (ctx) {
301
         builder: (ctx) {
308
         },
314
         },
309
       ),
315
       ),
310
     ).then((v) {
316
     ).then((v) {
311
-      if (handlePreviewResult(v)) {
312
-        Navigator.pop(context, v);
313
-        return;
314
-      }
315
-      isPushed = false;
316
-      setState(() {});
317
+      // if (handlePreviewResult(v)) {
318
+      //   sure();
319
+      //   return;
320
+      // }
321
+      sure();
322
+      // isPushed = false;
323
+      // setState(() {});
317
     });
324
     });
318
   }
325
   }
319
 
326
 
320
-  bool handlePreviewResult(List<AssetEntity> v) {
327
+  bool handlePreviewResult(PickedEntity v) {
321
     if (v == null) {
328
     if (v == null) {
322
       return false;
329
       return false;
323
     }
330
     }
324
-    if (v is List<AssetEntity>) {
331
+    if (v is PickedEntity) {
325
       return true;
332
       return true;
326
     }
333
     }
327
     return false;
334
     return false;

+ 19
- 11
lib/src/ui/page/photo_main_page.dart View File

23
 part './main/image_item.dart';
23
 part './main/image_item.dart';
24
 
24
 
25
 class PhotoMainPage extends StatefulWidget {
25
 class PhotoMainPage extends StatefulWidget {
26
-  final ValueChanged<List<AssetEntity>> onClose;
26
+  final ValueChanged<PickedEntity> onClose;
27
   final Options options;
27
   final Options options;
28
   final List<AssetPathEntity> photoList;
28
   final List<AssetPathEntity> photoList;
29
 
29
 
39
 }
39
 }
40
 
40
 
41
 class _PhotoMainPageState extends State<PhotoMainPage>
41
 class _PhotoMainPageState extends State<PhotoMainPage>
42
-    with SelectedProvider, GalleryListProvider {
42
+    with SelectedProvider, GalleryListProvider, WidgetsBindingObserver {
43
   PhotoProvider get config =>
43
   PhotoProvider get config =>
44
       Provider.of<PhotoProvider>(context, listen: false);
44
       Provider.of<PhotoProvider>(context, listen: false);
45
   Options get options => widget.options;
45
   Options get options => widget.options;
76
     _changeThrottle = Throttle(onCall: _onAssetChange);
76
     _changeThrottle = Throttle(onCall: _onAssetChange);
77
     PhotoManager.addChangeCallback(_changeThrottle.call);
77
     PhotoManager.addChangeCallback(_changeThrottle.call);
78
     PhotoManager.startChangeNotify();
78
     PhotoManager.startChangeNotify();
79
+    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
80
+      if (!_isInit) {
81
+        final pickedList = config.pickedAssetList ?? [];
82
+        addPickedAsset(pickedList.toList());
83
+        _refreshList();
84
+      }
85
+    });
79
   }
86
   }
80
 
87
 
81
   @override
88
   @override
82
   void didChangeDependencies() {
89
   void didChangeDependencies() {
83
     super.didChangeDependencies();
90
     super.didChangeDependencies();
84
-    if (!_isInit) {
85
-      final pickedList = config.pickedAssetList ?? [];
86
-      addPickedAsset(pickedList.toList());
87
-      _refreshList();
88
-    }
89
   }
91
   }
90
 
92
 
91
   @override
93
   @override
233
       return;
235
       return;
234
     }
236
     }
235
     selectedList.clear();
237
     selectedList.clear();
236
-    widget.onClose(selectedList);
238
+    widget.onClose(PickedEntity(
239
+      asset: selectedList,
240
+      isFullImage: isFullImage,
241
+    ));
237
   }
242
   }
238
 
243
 
239
   @override
244
   @override
244
   }
249
   }
245
 
250
 
246
   void sure() {
251
   void sure() {
247
-    widget.onClose?.call(selectedList);
252
+    widget.onClose?.call(PickedEntity(
253
+      asset: selectedList,
254
+      isFullImage: isFullImage,
255
+    ));
248
   }
256
   }
249
 
257
 
250
   void _showTip(String msg) {
258
   void _showTip(String msg) {
518
     setState(() {});
526
     setState(() {});
519
   }
527
   }
520
 
528
 
521
-  bool handlePreviewResult(List<AssetEntity> v) {
529
+  bool handlePreviewResult(PickedEntity v) {
522
     if (v == null) {
530
     if (v == null) {
523
       return false;
531
       return false;
524
     }
532
     }
525
-    if (v is List<AssetEntity>) {
533
+    if (v is PickedEntity) {
526
       return true;
534
       return true;
527
     }
535
     }
528
     return false;
536
     return false;

+ 5
- 1
lib/src/ui/page/photo_preview_page.dart View File

238
                 child: GestureDetector(
238
                 child: GestureDetector(
239
                   onTap: () {
239
                   onTap: () {
240
                     widget.selectedProvider.isFullImage = !snapshot.data;
240
                     widget.selectedProvider.isFullImage = !snapshot.data;
241
+                    // config.setFullImage(!snapshot.data);
241
                     isFullChangeController.add(selectedProvider.isFullImage);
242
                     isFullChangeController.add(selectedProvider.isFullImage);
242
                   },
243
                   },
243
                   behavior: HitTestBehavior.translucent,
244
                   behavior: HitTestBehavior.translucent,
382
   }
383
   }
383
 
384
 
384
   void sure() {
385
   void sure() {
385
-    Navigator.pop(context, selectedList);
386
+    Navigator.pop(context, PickedEntity(
387
+      asset: selectedList,
388
+      isFullImage: selectedProvider.isFullImage,
389
+    ));
386
   }
390
   }
387
 }
391
 }
388
 
392