Explorar el Código

Merge pull request #5 from CaiJingLong/loading_delegate

support custom loading widget delegate

update version 0.1.1
CaiJingLong hace 6 años
padre
commit
9fca109aa0
No account linked to committer's email address

+ 8
- 0
CHANGELOG.md Ver fichero

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

+ 36
- 33
README.md Ver fichero

@@ -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.
@@ -24,7 +24,7 @@ so PhotoPicker.pickImage return type will change to List<AssetEntity>
24 24
 
25 25
 ```yaml
26 26
 dependencies:
27
-  photo: ^0.1.0
27
+  photo: ^0.1.1
28 28
 ```
29 29
 
30 30
 ## import
@@ -37,43 +37,48 @@ import 'package:photo_manager/photo_manager.dart';
37 37
 ## use
38 38
 
39 39
 ```dart
40
-  void _pickImage() async {
40
+void _pickImage() async {
41 41
     List<AssetEntity> imgList = await PhotoPicker.pickImage(
42
-      context: context, // BuildContext requied
42
+      context: context,
43
+      // BuildContext requied
43 44
 
44 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 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 83
 ## about android
79 84
 
@@ -104,12 +109,10 @@ if you use the proguard
104 109
 
105 110
 see the [github](https://github.com/bumptech/glide#proguard)
106 111
 
107
-
108 112
 ## about ios
109 113
 
110 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 116
 like next
114 117
 
115 118
 ```plist
@@ -118,4 +121,4 @@ like next
118 121
 ```
119 122
 
120 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 Ver fichero

@@ -1,3 +1,4 @@
1
+import 'package:flutter/cupertino.dart';
1 2
 import 'package:flutter/material.dart';
2 3
 import 'package:photo/photo.dart';
3 4
 import 'package:photo_manager/photo_manager.dart';
@@ -26,32 +27,44 @@ class MyHomePage extends StatefulWidget {
26 27
   _MyHomePageState createState() => new _MyHomePageState();
27 28
 }
28 29
 
29
-class _MyHomePageState extends State<MyHomePage> {
30
+class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
30 31
   String currentSelected = "";
31 32
 
32 33
   void _pickImage() async {
33 34
     List<AssetEntity> imgList = await PhotoPicker.pickImage(
34
-      context: context, // BuildContext requied
35
+      context: context,
36
+      // BuildContext requied
35 37
 
36 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 70
     if (imgList == null) {
@@ -67,6 +80,34 @@ class _MyHomePageState extends State<MyHomePage> {
67 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 111
   @override
71 112
   Widget build(BuildContext context) {
72 113
     return new Scaffold(

+ 1
- 1
example/test/widget_test.dart Ver fichero

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

+ 11
- 6
lib/photo.dart Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

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

+ 8
- 2
lib/src/ui/page/photo_preview_page.dart Ver fichero

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

+ 1
- 1
pubspec.lock Ver fichero

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

+ 2
- 2
pubspec.yaml Ver fichero

@@ -1,6 +1,6 @@
1 1
 name: photo
2 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 4
 author: caijinglong<cjl_spy@163.com>
5 5
 homepage: https://github.com/CaiJingLong/flutter_photo
6 6
 
@@ -11,7 +11,7 @@ dependencies:
11 11
   flutter:
12 12
     sdk: flutter
13 13
 
14
-  photo_manager: ^0.1.0
14
+  photo_manager: ^0.1.2
15 15
 #  photo_manager:
16 16
 #    git:
17 17
 #      url: https://github.com/CaiJingLong/flutter_photo_manager.git

+ 2
- 2
test/photo_test.dart Ver fichero

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