Parcourir la source

support custom loading widget delegate

Caijinglong il y a 6 ans
Parent
révision
a99ce11147

+ 4
- 0
CHANGELOG.md Voir le fichier

@@ -1,17 +1,21 @@
1 1
 # CHANGELOG
2 2
 
3 3
 ## [0.1.0] support video
4
+
4 5
 API incompatibility
5 6
 
6 7
 ImageXXX rename AssetXXX
7 8
 
8 9
 ## [0.0.8] fix bug
10
+
9 11
 DefaultCheckBoxBuilderDelegate params checkColor not valid bug
10 12
 
11 13
 ## [0.0.7] fix bug
14
+
12 15
 fix dividerColor not valid bug
13 16
 
14 17
 ## [0.0.6] add checkbox delegate
18
+
15 19
 users can use CheckBoxDelegate to custom preview right bottom widget
16 20
 
17 21
 ## [0.0.5] add a params

+ 3
- 6
README.md Voir le fichier

@@ -3,7 +3,6 @@
3 3
 [![pub package](https://img.shields.io/pub/v/photo.svg)](https://pub.dartlang.org/packages/photo)
4 4
 ![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)
5 5
 
6
-
7 6
 image picker, multi picker
8 7
 use flutter as ui
9 8
 
@@ -14,6 +13,7 @@ if you want to build custom ui, you just need api to make custom ui. to use [pho
14 13
 ![image](https://github.com/CaiJingLong/some_asset/blob/master/image_picker1.gif)
15 14
 
16 15
 ## API incompatibility
16
+
17 17
 API incompatibility
18 18
 
19 19
 because support video, so the ImagePathEntity and ImageEntity rename to AssetPathEntity and AssetEntity.
@@ -68,12 +68,11 @@ import 'package:photo_manager/photo_manager.dart';
68 68
     }
69 69
     setState(() {});
70 70
   }
71
-
72 71
 ```
73 72
 
74 73
 ## whole example
75 74
 
76
-you can see [github](https://github.com/caijinglong/flutter_photo/blob/master/example/)  [main.dart](https://github.com/caijinglong/flutter_photo/blob/master/example/lib/main.dart)
75
+you can see [github](https://github.com/caijinglong/flutter_photo/blob/master/example/) [main.dart](https://github.com/caijinglong/flutter_photo/blob/master/example/lib/main.dart)
77 76
 
78 77
 ## about android
79 78
 
@@ -104,12 +103,10 @@ if you use the proguard
104 103
 
105 104
 see the [github](https://github.com/bumptech/glide#proguard)
106 105
 
107
-
108 106
 ## about ios
109 107
 
110 108
 Because the album is a privacy privilege, you need user permission to access it. You must to modify the `Info.plist` file in Runner project.
111 109
 
112
-
113 110
 like next
114 111
 
115 112
 ```plist
@@ -118,4 +115,4 @@ like next
118 115
 ```
119 116
 
120 117
 xcode like image
121
-![in xcode](https://github.com/CaiJingLong/some_asset/blob/master/flutter_photo2.png)
118
+![in xcode](https://github.com/CaiJingLong/some_asset/blob/master/flutter_photo2.png)

+ 11
- 6
lib/photo.dart Voir le fichier

@@ -3,19 +3,20 @@ library photo;
3 3
 import 'dart:async';
4 4
 
5 5
 import 'package:flutter/material.dart';
6
-import 'package:photo_manager/photo_manager.dart';
7
-
6
+import 'package:photo/src/delegate/checkbox_builder_delegate.dart';
7
+import 'package:photo/src/delegate/loading_delegate.dart';
8
+import 'package:photo/src/delegate/sort_delegate.dart';
8 9
 import 'package:photo/src/entity/options.dart';
9 10
 import 'package:photo/src/provider/i18n_provider.dart';
10 11
 import 'package:photo/src/ui/dialog/not_permission_dialog.dart';
11 12
 import 'package:photo/src/ui/photo_app.dart';
12
-import 'package:photo/src/delegate/sort_delegate.dart';
13
-import 'package:photo/src/delegate/checkbox_builder_delegate.dart';
13
+import 'package:photo_manager/photo_manager.dart';
14 14
 
15
+export 'package:photo/src/delegate/checkbox_builder_delegate.dart';
16
+export 'package:photo/src/delegate/loading_delegate.dart';
17
+export 'package:photo/src/delegate/sort_delegate.dart';
15 18
 export 'package:photo/src/provider/i18n_provider.dart'
16 19
     show I18NCustomProvider, I18nProvider, CNProvider, ENProvider;
17
-export 'package:photo/src/delegate/sort_delegate.dart';
18
-export 'package:photo/src/delegate/checkbox_builder_delegate.dart';
19 20
 
20 21
 class PhotoPicker {
21 22
   static PhotoPicker _instance;
@@ -61,6 +62,7 @@ class PhotoPicker {
61 62
     I18nProvider provider = I18nProvider.chinese,
62 63
     SortDelegate sortDelegate,
63 64
     CheckBoxBuilderDelegate checkBoxBuilderDelegate,
65
+    LoadingDelegate loadingDelegate,
64 66
   }) {
65 67
     assert(provider != null, "provider must be not null");
66 68
     assert(context != null, "context must be not null");
@@ -73,6 +75,8 @@ class PhotoPicker {
73 75
     sortDelegate ??= SortDelegate.common;
74 76
     checkBoxBuilderDelegate ??= DefaultCheckBoxBuilderDelegate();
75 77
 
78
+    loadingDelegate ??= DefaultLoadingDelegate();
79
+
76 80
     var options = Options(
77 81
       rowCount: rowCount,
78 82
       dividerColor: dividerColor,
@@ -85,6 +89,7 @@ class PhotoPicker {
85 89
       thumbSize: thumbSize,
86 90
       sortDelegate: sortDelegate,
87 91
       checkBoxBuilderDelegate: checkBoxBuilderDelegate,
92
+      loadingDelegate: loadingDelegate,
88 93
     );
89 94
 
90 95
     return PhotoPicker()._pickImage(

+ 40
- 0
lib/src/delegate/loading_delegate.dart Voir le fichier

@@ -0,0 +1,40 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:photo_manager/photo_manager.dart';
3
+
4
+abstract class LoadingDelegate {
5
+  Widget buildBigImageLoading(
6
+      BuildContext context, AssetEntity entity, Color themeColor);
7
+
8
+  Widget buildPreviewLoading(
9
+      BuildContext context, AssetEntity entity, Color themeColor);
10
+}
11
+
12
+class DefaultLoadingDelegate extends LoadingDelegate {
13
+  @override
14
+  Widget buildBigImageLoading(
15
+      BuildContext context, AssetEntity entity, Color themeColor) {
16
+    return Center(
17
+      child: Container(
18
+        width: 30.0,
19
+        height: 30.0,
20
+        child: CircularProgressIndicator(
21
+          valueColor: AlwaysStoppedAnimation(themeColor),
22
+        ),
23
+      ),
24
+    );
25
+  }
26
+
27
+  @override
28
+  Widget buildPreviewLoading(
29
+      BuildContext context, AssetEntity entity, Color themeColor) {
30
+    return Center(
31
+      child: Container(
32
+        width: 30.0,
33
+        height: 30.0,
34
+        child: CircularProgressIndicator(
35
+          valueColor: AlwaysStoppedAnimation(themeColor),
36
+        ),
37
+      ),
38
+    );
39
+  }
40
+}

+ 4
- 0
lib/src/entity/options.dart Voir le fichier

@@ -1,5 +1,6 @@
1 1
 import 'package:flutter/material.dart';
2 2
 import 'package:photo/src/delegate/checkbox_builder_delegate.dart';
3
+import 'package:photo/src/delegate/loading_delegate.dart';
3 4
 import 'package:photo/src/delegate/sort_delegate.dart';
4 5
 
5 6
 class Options {
@@ -25,6 +26,8 @@ class Options {
25 26
 
26 27
   final CheckBoxBuilderDelegate checkBoxBuilderDelegate;
27 28
 
29
+  final LoadingDelegate loadingDelegate;
30
+
28 31
   const Options({
29 32
     this.rowCount,
30 33
     this.maxSelected,
@@ -37,5 +40,6 @@ class Options {
37 40
     this.thumbSize,
38 41
     this.sortDelegate,
39 42
     this.checkBoxBuilderDelegate,
43
+    this.loadingDelegate,
40 44
   });
41 45
 }

+ 7
- 7
lib/src/ui/page/photo_main_page.dart Voir le fichier

@@ -1,6 +1,7 @@
1 1
 import 'dart:typed_data';
2 2
 
3 3
 import 'package:flutter/material.dart';
4
+import 'package:photo/src/delegate/loading_delegate.dart';
4 5
 import 'package:photo/src/engine/lru_cache.dart';
5 6
 import 'package:photo/src/entity/options.dart';
6 7
 import 'package:photo/src/provider/config_provider.dart';
@@ -197,6 +198,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
197 198
             entity: data,
198 199
             themeColor: themeColor,
199 200
             size: options.thumbSize,
201
+            loadingDelegate: options.loadingDelegate,
200 202
           ),
201 203
           _buildMask(containsEntity(data)),
202 204
           _buildSelected(data),
@@ -487,11 +489,14 @@ class ImageItem extends StatelessWidget {
487 489
 
488 490
   final int size;
489 491
 
492
+  final LoadingDelegate loadingDelegate;
493
+
490 494
   const ImageItem({
491 495
     Key key,
492 496
     this.entity,
493 497
     this.themeColor,
494 498
     this.size = 64,
499
+    this.loadingDelegate,
495 500
   }) : super(key: key);
496 501
 
497 502
   @override
@@ -511,13 +516,8 @@ class ImageItem extends StatelessWidget {
511 516
           return _buildImageItem(futureData);
512 517
         }
513 518
         return Center(
514
-          child: Container(
515
-            width: 20.0,
516
-            height: 20.0,
517
-            child: CircularProgressIndicator(
518
-              valueColor: AlwaysStoppedAnimation(themeColor),
519
-            ),
520
-          ),
519
+          child:
520
+              loadingDelegate.buildPreviewLoading(context, entity, themeColor),
521 521
         );
522 522
       },
523 523
     );

+ 7
- 2
lib/src/ui/page/photo_preview_page.dart Voir le fichier

@@ -238,9 +238,14 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
238 238
     var data = list[index];
239 239
     return BigPhotoImage(
240 240
       assetEntity: data,
241
+      loadingWidget: _buildLoadingWidget(data),
241 242
     );
242 243
   }
243 244
 
245
+  Widget _buildLoadingWidget(AssetEntity entity) {
246
+    return options.loadingDelegate.buildBigImageLoading(context, entity, themeColor);
247
+  }
248
+
244 249
   void _onPageChanged(int value) {
245 250
     pageChangeController.add(value);
246 251
   }
@@ -271,6 +276,7 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
271 276
               themeColor: themeColor,
272 277
               entity: item,
273 278
               size: options.thumbSize,
279
+              loadingDelegate: options.loadingDelegate,
274 280
             ),
275 281
             IgnorePointer(
276 282
               child: StreamBuilder(
@@ -317,8 +323,7 @@ class BigPhotoImage extends StatefulWidget {
317 323
 
318 324
 class _BigPhotoImageState extends State<BigPhotoImage>
319 325
     with AutomaticKeepAliveClientMixin {
320
-
321
-  Widget get loadingWidget{
326
+  Widget get loadingWidget {
322 327
     return widget.loadingWidget ?? Container();
323 328
   }
324 329