Browse Source

Merge pull request #5 from CaiJingLong/loading_delegate

support custom loading widget delegate

update version 0.1.1
CaiJingLong 6 years ago
parent
commit
9fca109aa0
No account linked to committer's email address

+ 8
- 0
CHANGELOG.md View File

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

+ 36
- 33
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.
24
 
24
 
25
 ```yaml
25
 ```yaml
26
 dependencies:
26
 dependencies:
27
-  photo: ^0.1.0
27
+  photo: ^0.1.1
28
 ```
28
 ```
29
 
29
 
30
 ## import
30
 ## import
37
 ## use
37
 ## use
38
 
38
 
39
 ```dart
39
 ```dart
40
-  void _pickImage() async {
40
+void _pickImage() async {
41
     List<AssetEntity> imgList = await PhotoPicker.pickImage(
41
     List<AssetEntity> imgList = await PhotoPicker.pickImage(
42
-      context: context, // BuildContext requied
42
+      context: context,
43
+      // BuildContext requied
43
 
44
 
44
       /// The following are optional parameters.
45
       /// The following are optional parameters.
45
-      themeColor: Colors.green, // the title color and bottom color
46
-      padding: 1.0, // item padding
47
-      dividerColor: Colors.deepOrange, // divider color
48
-      disableColor: Colors.grey.shade300, // the check box disable color
49
-      itemRadio: 0.88, // the content item radio
50
-      maxSelected: 8, // max picker image count
51
-      provider: I18nProvider.chinese, // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
52
-      rowCount: 5,  // item row count
53
-      textColor: Colors.white, // text color
54
-      thumbSize: 150, // preview thumb size , default is 64
55
-      sortDelegate: SortDelegate.common, // default is common ,or you make custom delegate to sort your gallery
56
-      checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
46
+      themeColor: Colors.green,
47
+      // the title color and bottom color
48
+      padding: 1.0,
49
+      // item padding
50
+      dividerColor: Colors.grey,
51
+      // divider color
52
+      disableColor: Colors.grey.shade300,
53
+      // the check box disable color
54
+      itemRadio: 0.88,
55
+      // the content item radio
56
+      maxSelected: 8,
57
+      // max picker image count
58
+      provider: I18nProvider.chinese,
59
+      // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
60
+      rowCount: 5,
61
+      // item row count
62
+      textColor: Colors.white,
63
+      // text color
64
+      thumbSize: 150,
65
+      // preview thumb size , default is 64
66
+      sortDelegate: SortDelegate.common,
67
+      // default is common ,or you make custom delegate to sort your gallery
68
+      checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
69
+        activeColor: Colors.white,
70
+        unselectedColor: Colors.white,
71
+      ), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
72
+
73
+      loadingDelegate:
74
+          this, // if you want to build custom loading widget,extends LoadingDelegate [see example/lib/main.dart]
57
     );
75
     );
58
 
76
 
59
-    if (imgList == null) {
60
-      currentSelected = "not select item";
61
-    } else {
62
-      List<String> r = [];
63
-      for (var e in imgList) {
64
-        var file = await e.file;
65
-        r.add(file.absolute.path);
66
-      }
67
-      currentSelected = r.join("\n\n");
68
-    }
69
-    setState(() {});
70
-  }
71
-
72
 ```
77
 ```
73
 
78
 
74
 ## whole example
79
 ## whole example
75
 
80
 
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)
81
+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
 
82
 
78
 ## about android
83
 ## about android
79
 
84
 
104
 
109
 
105
 see the [github](https://github.com/bumptech/glide#proguard)
110
 see the [github](https://github.com/bumptech/glide#proguard)
106
 
111
 
107
-
108
 ## about ios
112
 ## about ios
109
 
113
 
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.
114
 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
 
115
 
112
-
113
 like next
116
 like next
114
 
117
 
115
 ```plist
118
 ```plist
118
 ```
121
 ```
119
 
122
 
120
 xcode like image
123
 xcode like image
121
-![in xcode](https://github.com/CaiJingLong/some_asset/blob/master/flutter_photo2.png)
124
+![in xcode](https://github.com/CaiJingLong/some_asset/blob/master/flutter_photo2.png)

+ 61
- 20
example/lib/main.dart View File

1
+import 'package:flutter/cupertino.dart';
1
 import 'package:flutter/material.dart';
2
 import 'package:flutter/material.dart';
2
 import 'package:photo/photo.dart';
3
 import 'package:photo/photo.dart';
3
 import 'package:photo_manager/photo_manager.dart';
4
 import 'package:photo_manager/photo_manager.dart';
26
   _MyHomePageState createState() => new _MyHomePageState();
27
   _MyHomePageState createState() => new _MyHomePageState();
27
 }
28
 }
28
 
29
 
29
-class _MyHomePageState extends State<MyHomePage> {
30
+class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
30
   String currentSelected = "";
31
   String currentSelected = "";
31
 
32
 
32
   void _pickImage() async {
33
   void _pickImage() async {
33
     List<AssetEntity> imgList = await PhotoPicker.pickImage(
34
     List<AssetEntity> imgList = await PhotoPicker.pickImage(
34
-      context: context, // BuildContext requied
35
+      context: context,
36
+      // BuildContext requied
35
 
37
 
36
       /// The following are optional parameters.
38
       /// The following are optional parameters.
37
-      themeColor: Colors.green, // the title color and bottom color
38
-      padding: 1.0, // item padding
39
-      dividerColor: Colors.grey, // divider color
40
-      disableColor: Colors.grey.shade300, // the check box disable color
41
-      itemRadio: 0.88, // the content item radio
42
-      maxSelected: 8, // max picker image count
43
-      provider: I18nProvider
44
-          .chinese, // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
45
-      rowCount: 5, // item row count
46
-      textColor: Colors.white, // text color
47
-      thumbSize: 150, // preview thumb size , default is 64
48
-      sortDelegate: SortDelegate
49
-          .common, // default is common ,or you make custom delegate to sort your gallery
50
-      checkBoxBuilderDelegate:
51
-          DefaultCheckBoxBuilderDelegate(
52
-            activeColor: Colors.white,
53
-            unselectedColor: Colors.white,
54
-          ), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
39
+      themeColor: Colors.green,
40
+      // the title color and bottom color
41
+      padding: 1.0,
42
+      // item padding
43
+      dividerColor: Colors.grey,
44
+      // divider color
45
+      disableColor: Colors.grey.shade300,
46
+      // the check box disable color
47
+      itemRadio: 0.88,
48
+      // the content item radio
49
+      maxSelected: 8,
50
+      // max picker image count
51
+      provider: I18nProvider.chinese,
52
+      // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
53
+      rowCount: 5,
54
+      // item row count
55
+      textColor: Colors.white,
56
+      // text color
57
+      thumbSize: 150,
58
+      // preview thumb size , default is 64
59
+      sortDelegate: SortDelegate.common,
60
+      // default is common ,or you make custom delegate to sort your gallery
61
+      checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
62
+        activeColor: Colors.white,
63
+        unselectedColor: Colors.white,
64
+      ), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
65
+
66
+      loadingDelegate:
67
+          this, // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
55
     );
68
     );
56
 
69
 
57
     if (imgList == null) {
70
     if (imgList == null) {
67
     setState(() {});
80
     setState(() {});
68
   }
81
   }
69
 
82
 
83
+  @override
84
+  Widget buildBigImageLoading(
85
+      BuildContext context, AssetEntity entity, Color themeColor) {
86
+    return Center(
87
+      child: Container(
88
+        width: 50.0,
89
+        height: 50.0,
90
+        child: CupertinoActivityIndicator(
91
+          radius: 25.0,
92
+        ),
93
+      ),
94
+    );
95
+  }
96
+
97
+  @override
98
+  Widget buildPreviewLoading(
99
+      BuildContext context, AssetEntity entity, Color themeColor) {
100
+    return Center(
101
+      child: Container(
102
+        width: 50.0,
103
+        height: 50.0,
104
+        child: CupertinoActivityIndicator(
105
+          radius: 25.0,
106
+        ),
107
+      ),
108
+    );
109
+  }
110
+
70
   @override
111
   @override
71
   Widget build(BuildContext context) {
112
   Widget build(BuildContext context) {
72
     return new Scaffold(
113
     return new Scaffold(

+ 1
- 1
example/test/widget_test.dart View File

7
 import 'package:flutter/material.dart';
7
 import 'package:flutter/material.dart';
8
 import 'package:flutter_test/flutter_test.dart';
8
 import 'package:flutter_test/flutter_test.dart';
9
 
9
 
10
-import 'package:example/main.dart';
10
+import '../lib/main.dart';
11
 
11
 
12
 void main() {
12
 void main() {
13
   testWidgets('Counter increments smoke test', (WidgetTester tester) async {
13
   testWidgets('Counter increments smoke test', (WidgetTester tester) async {

+ 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
     );

+ 8
- 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
247
+        .buildBigImageLoading(context, entity, themeColor);
248
+  }
249
+
244
   void _onPageChanged(int value) {
250
   void _onPageChanged(int value) {
245
     pageChangeController.add(value);
251
     pageChangeController.add(value);
246
   }
252
   }
271
               themeColor: themeColor,
277
               themeColor: themeColor,
272
               entity: item,
278
               entity: item,
273
               size: options.thumbSize,
279
               size: options.thumbSize,
280
+              loadingDelegate: options.loadingDelegate,
274
             ),
281
             ),
275
             IgnorePointer(
282
             IgnorePointer(
276
               child: StreamBuilder(
283
               child: StreamBuilder(
317
 
324
 
318
 class _BigPhotoImageState extends State<BigPhotoImage>
325
 class _BigPhotoImageState extends State<BigPhotoImage>
319
     with AutomaticKeepAliveClientMixin {
326
     with AutomaticKeepAliveClientMixin {
320
-
321
-  Widget get loadingWidget{
327
+  Widget get loadingWidget {
322
     return widget.loadingWidget ?? Container();
328
     return widget.loadingWidget ?? Container();
323
   }
329
   }
324
 
330
 

+ 1
- 1
pubspec.lock View File

213
       name: photo_manager
213
       name: photo_manager
214
       url: "https://pub.flutter-io.cn"
214
       url: "https://pub.flutter-io.cn"
215
     source: hosted
215
     source: hosted
216
-    version: "0.1.0"
216
+    version: "0.1.2"
217
   plugin:
217
   plugin:
218
     dependency: transitive
218
     dependency: transitive
219
     description:
219
     description:

+ 2
- 2
pubspec.yaml View File

1
 name: photo
1
 name: photo
2
 description: image picker, multi picker,use flutter as ui, if you want to build custom ui,you just use photo_manager.
2
 description: image picker, multi picker,use flutter as ui, if you want to build custom ui,you just use photo_manager.
3
-version: 0.1.0
3
+version: 0.1.1
4
 author: caijinglong<cjl_spy@163.com>
4
 author: caijinglong<cjl_spy@163.com>
5
 homepage: https://github.com/CaiJingLong/flutter_photo
5
 homepage: https://github.com/CaiJingLong/flutter_photo
6
 
6
 
11
   flutter:
11
   flutter:
12
     sdk: flutter
12
     sdk: flutter
13
 
13
 
14
-  photo_manager: ^0.1.0
14
+  photo_manager: ^0.1.2
15
 #  photo_manager:
15
 #  photo_manager:
16
 #    git:
16
 #    git:
17
 #      url: https://github.com/CaiJingLong/flutter_photo_manager.git
17
 #      url: https://github.com/CaiJingLong/flutter_photo_manager.git

+ 2
- 2
test/photo_test.dart View File

1
-import 'package:test/test.dart';
1
+//import 'package:test/test.dart';
2
 
2
 
3
 void main() {
3
 void main() {
4
-  test('adds one to input values', () {});
4
+//  test('adds one to input values', () {});
5
 }
5
 }