Browse Source

support custom loading widget delegate

Caijinglong 6 years ago
parent
commit
a99ce11147

+ 4
- 0
CHANGELOG.md View File

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

+ 3
- 6
README.md View File

3
 [![pub package](https://img.shields.io/pub/v/photo.svg)](https://pub.dartlang.org/packages/photo)
3
 [![pub package](https://img.shields.io/pub/v/photo.svg)](https://pub.dartlang.org/packages/photo)
4
 ![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)
4
 ![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)
5
 
5
 
6
-
7
 image picker, multi picker
6
 image picker, multi picker
8
 use flutter as ui
7
 use flutter as ui
9
 
8
 
14
 ![image](https://github.com/CaiJingLong/some_asset/blob/master/image_picker1.gif)
13
 ![image](https://github.com/CaiJingLong/some_asset/blob/master/image_picker1.gif)
15
 
14
 
16
 ## API incompatibility
15
 ## API incompatibility
16
+
17
 API incompatibility
17
 API incompatibility
18
 
18
 
19
 because support video, so the ImagePathEntity and ImageEntity rename to AssetPathEntity and AssetEntity.
19
 because support video, so the ImagePathEntity and ImageEntity rename to AssetPathEntity and AssetEntity.
68
     }
68
     }
69
     setState(() {});
69
     setState(() {});
70
   }
70
   }
71
-
72
 ```
71
 ```
73
 
72
 
74
 ## whole example
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
 ## about android
77
 ## about android
79
 
78
 
104
 
103
 
105
 see the [github](https://github.com/bumptech/glide#proguard)
104
 see the [github](https://github.com/bumptech/glide#proguard)
106
 
105
 
107
-
108
 ## about ios
106
 ## about ios
109
 
107
 
110
 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.
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
 like next
110
 like next
114
 
111
 
115
 ```plist
112
 ```plist
118
 ```
115
 ```
119
 
116
 
120
 xcode like image
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 View File

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

+ 40
- 0
lib/src/delegate/loading_delegate.dart View File

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 View File

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

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

1
 import 'dart:typed_data';
1
 import 'dart:typed_data';
2
 
2
 
3
 import 'package:flutter/material.dart';
3
 import 'package:flutter/material.dart';
4
+import 'package:photo/src/delegate/loading_delegate.dart';
4
 import 'package:photo/src/engine/lru_cache.dart';
5
 import 'package:photo/src/engine/lru_cache.dart';
5
 import 'package:photo/src/entity/options.dart';
6
 import 'package:photo/src/entity/options.dart';
6
 import 'package:photo/src/provider/config_provider.dart';
7
 import 'package:photo/src/provider/config_provider.dart';
197
             entity: data,
198
             entity: data,
198
             themeColor: themeColor,
199
             themeColor: themeColor,
199
             size: options.thumbSize,
200
             size: options.thumbSize,
201
+            loadingDelegate: options.loadingDelegate,
200
           ),
202
           ),
201
           _buildMask(containsEntity(data)),
203
           _buildMask(containsEntity(data)),
202
           _buildSelected(data),
204
           _buildSelected(data),
487
 
489
 
488
   final int size;
490
   final int size;
489
 
491
 
492
+  final LoadingDelegate loadingDelegate;
493
+
490
   const ImageItem({
494
   const ImageItem({
491
     Key key,
495
     Key key,
492
     this.entity,
496
     this.entity,
493
     this.themeColor,
497
     this.themeColor,
494
     this.size = 64,
498
     this.size = 64,
499
+    this.loadingDelegate,
495
   }) : super(key: key);
500
   }) : super(key: key);
496
 
501
 
497
   @override
502
   @override
511
           return _buildImageItem(futureData);
516
           return _buildImageItem(futureData);
512
         }
517
         }
513
         return Center(
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 View File

238
     var data = list[index];
238
     var data = list[index];
239
     return BigPhotoImage(
239
     return BigPhotoImage(
240
       assetEntity: data,
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
   void _onPageChanged(int value) {
249
   void _onPageChanged(int value) {
245
     pageChangeController.add(value);
250
     pageChangeController.add(value);
246
   }
251
   }
271
               themeColor: themeColor,
276
               themeColor: themeColor,
272
               entity: item,
277
               entity: item,
273
               size: options.thumbSize,
278
               size: options.thumbSize,
279
+              loadingDelegate: options.loadingDelegate,
274
             ),
280
             ),
275
             IgnorePointer(
281
             IgnorePointer(
276
               child: StreamBuilder(
282
               child: StreamBuilder(
317
 
323
 
318
 class _BigPhotoImageState extends State<BigPhotoImage>
324
 class _BigPhotoImageState extends State<BigPhotoImage>
319
     with AutomaticKeepAliveClientMixin {
325
     with AutomaticKeepAliveClientMixin {
320
-
321
-  Widget get loadingWidget{
326
+  Widget get loadingWidget {
322
     return widget.loadingWidget ?? Container();
327
     return widget.loadingWidget ?? Container();
323
   }
328
   }
324
 
329