Explorar el Código

fix is_full radio

lucky1213 hace 4 años
padre
commit
ba5d1c84fb

+ 17
- 17
example/lib/main.dart Ver fichero

@@ -120,23 +120,23 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
120 120
                 text: "Picked asset example.",
121 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 Ver fichero

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

+ 7
- 0
lib/src/entity/options.dart Ver fichero

@@ -4,6 +4,7 @@ import 'package:photo/src/delegate/checkbox_builder_delegate.dart';
4 4
 import 'package:photo/src/delegate/loading_delegate.dart';
5 5
 import 'package:photo/src/delegate/sort_delegate.dart';
6 6
 import 'package:photo/src/entity/_theme.dart';
7
+import 'package:photo_manager/photo_manager.dart';
7 8
 
8 9
 class Options {
9 10
   final int rowCount;
@@ -78,3 +79,9 @@ enum PickType {
78 79
   onlyImage,
79 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 Ver fichero

@@ -7,16 +7,22 @@ import 'package:photo_manager/photo_manager.dart';
7 7
 // ignore_for_file: deprecated_member_use
8 8
 
9 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 15
   PhotoProvider({
15 16
     @required this.options,
16 17
     @required this.provider,
17 18
     List<AssetEntity> pickedAssetList,
19
+    this.isFullImage = false,
18 20
   }) : this.pickedAssetList = pickedAssetList ?? [];
19 21
   
22
+  void setFullImage(bool value) {
23
+    isFullImage = value;
24
+    notifyListeners();
25
+  }
20 26
 
21 27
   @override
22 28
   void notifyListeners() {

+ 20
- 13
lib/src/ui/page/photo_list_page.dart Ver fichero

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

+ 19
- 11
lib/src/ui/page/photo_main_page.dart Ver fichero

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

+ 5
- 1
lib/src/ui/page/photo_preview_page.dart Ver fichero

@@ -238,6 +238,7 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
238 238
                 child: GestureDetector(
239 239
                   onTap: () {
240 240
                     widget.selectedProvider.isFullImage = !snapshot.data;
241
+                    // config.setFullImage(!snapshot.data);
241 242
                     isFullChangeController.add(selectedProvider.isFullImage);
242 243
                   },
243 244
                   behavior: HitTestBehavior.translucent,
@@ -382,7 +383,10 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
382 383
   }
383 384
 
384 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