Browse Source

update for gallery name

Caijinglong 5 years ago
parent
commit
4c5c716f9c

+ 2
- 2
README.md View File

77
 
77
 
78
       pickType: type, // all/image/video
78
       pickType: type, // all/image/video
79
 
79
 
80
-      List<AssetPathEntity> photoList, /// when [photoList] is not null , [pickType] invalid .
80
+      List<AssetPathEntity> photoPathList, /// when [photoPathList] is not null , [pickType] invalid .
81
     );
81
     );
82
 ```
82
 ```
83
 
83
 
84
-## about photoList
84
+### about photoPathList params
85
 
85
 
86
 You can use [photo_manager] package to get `List<AssetPathEntity>` and handle or cache.
86
 You can use [photo_manager] package to get `List<AssetPathEntity>` and handle or cache.
87
 
87
 

+ 70
- 57
example/lib/main.dart View File

30
 class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
30
 class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
31
   String currentSelected = "";
31
   String currentSelected = "";
32
 
32
 
33
-  void _pickAsset(PickType type) async {
34
-    List<AssetEntity> imgList = await PhotoPicker.pickAsset(
35
-      // BuildContext required
36
-      context: context,
37
-
38
-      /// The following are optional parameters.
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.english,
52
-      provider: I18nProvider.chinese,
53
-      // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
54
-      rowCount: 3,
55
-      // item row count
56
-      textColor: Colors.white,
57
-      // text color
58
-      thumbSize: 150,
59
-      // preview thumb size , default is 64
60
-      sortDelegate: SortDelegate.common,
61
-      // default is common ,or you make custom delegate to sort your gallery
62
-      checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
63
-        activeColor: Colors.white,
64
-        unselectedColor: Colors.white,
65
-      ),
66
-      // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
67
-
68
-      loadingDelegate: this,
69
-      // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
70
-
71
-      badgeDelegate: const DurationBadgeDelegate(),
72
-      // badgeDelegate to show badge widget
73
-
74
-      pickType: type,
75
-    );
76
-
77
-    if (imgList == null) {
78
-      currentSelected = "not select item";
79
-    } else {
80
-      List<String> r = [];
81
-      for (var e in imgList) {
82
-        var file = await e.file;
83
-        r.add(file.absolute.path);
84
-      }
85
-      currentSelected = r.join("\n\n");
86
-    }
87
-    setState(() {});
88
-  }
89
-
90
   @override
33
   @override
91
   Widget buildBigImageLoading(
34
   Widget buildBigImageLoading(
92
       BuildContext context, AssetEntity entity, Color themeColor) {
35
       BuildContext context, AssetEntity entity, Color themeColor) {
120
     return new Scaffold(
63
     return new Scaffold(
121
       appBar: new AppBar(
64
       appBar: new AppBar(
122
         title: new Text(widget.title),
65
         title: new Text(widget.title),
66
+        actions: <Widget>[
67
+          FlatButton(
68
+            child: Icon(Icons.image),
69
+            onPressed: _testPhotoListParams,
70
+          ),
71
+        ],
123
       ),
72
       ),
124
       body: Container(
73
       body: Container(
125
         child: SingleChildScrollView(
74
         child: SingleChildScrollView(
152
       ),
101
       ),
153
     );
102
     );
154
   }
103
   }
104
+
105
+  void _testPhotoListParams() async {
106
+    var assetPathList = await PhotoManager.getImageAsset();
107
+    _pickAsset(PickType.all, pathList: assetPathList);
108
+  }
109
+
110
+  void _pickAsset(PickType type, {List<AssetPathEntity> pathList}) async {
111
+    List<AssetEntity> imgList = await PhotoPicker.pickAsset(
112
+      // BuildContext required
113
+      context: context,
114
+
115
+      /// The following are optional parameters.
116
+      themeColor: Colors.green,
117
+      // the title color and bottom color
118
+      padding: 1.0,
119
+      // item padding
120
+      dividerColor: Colors.grey,
121
+      // divider color
122
+      disableColor: Colors.grey.shade300,
123
+      // the check box disable color
124
+      itemRadio: 0.88,
125
+      // the content item radio
126
+      maxSelected: 8,
127
+      // max picker image count
128
+      // provider: I18nProvider.english,
129
+      provider: I18nProvider.chinese,
130
+      // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
131
+      rowCount: 3,
132
+      // item row count
133
+      textColor: Colors.white,
134
+      // text color
135
+      thumbSize: 150,
136
+      // preview thumb size , default is 64
137
+      sortDelegate: SortDelegate.common,
138
+      // default is common ,or you make custom delegate to sort your gallery
139
+      checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
140
+        activeColor: Colors.white,
141
+        unselectedColor: Colors.white,
142
+      ),
143
+      // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
144
+
145
+      loadingDelegate: this,
146
+      // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
147
+
148
+      badgeDelegate: const DurationBadgeDelegate(),
149
+      // badgeDelegate to show badge widget
150
+
151
+      pickType: type,
152
+
153
+      photoPathList: pathList,
154
+    );
155
+
156
+    if (imgList == null) {
157
+      currentSelected = "not select item";
158
+    } else {
159
+      List<String> r = [];
160
+      for (var e in imgList) {
161
+        var file = await e.file;
162
+        r.add(file.absolute.path);
163
+      }
164
+      currentSelected = r.join("\n\n");
165
+    }
166
+    setState(() {});
167
+  }
155
 }
168
 }
156
 
169
 
157
 class IconTextButton extends StatelessWidget {
170
 class IconTextButton extends StatelessWidget {

+ 4
- 4
lib/photo.dart View File

44
   ///
44
   ///
45
   ///   当用户取消时返回一个空数组
45
   ///   当用户取消时返回一个空数组
46
   ///
46
   ///
47
-  ///   [photoList] 一旦设置 则 [pickType]参数无效
47
+  ///   [photoPathList] 一旦设置 则 [pickType]参数无效
48
   ///
48
   ///
49
   /// 关于参数可以查看readme文档介绍
49
   /// 关于参数可以查看readme文档介绍
50
   ///
50
   ///
57
   ///
57
   ///
58
   ///   when user cancel selected,result is empty list
58
   ///   when user cancel selected,result is empty list
59
   ///
59
   ///
60
-  ///   when [photoList] is not null , [pickType] invalid
60
+  ///   when [photoPathList] is not null , [pickType] invalid
61
   ///
61
   ///
62
   /// params see readme.md
62
   /// params see readme.md
63
   static Future<List<AssetEntity>> pickAsset({
63
   static Future<List<AssetEntity>> pickAsset({
77
     LoadingDelegate loadingDelegate,
77
     LoadingDelegate loadingDelegate,
78
     PickType pickType = PickType.all,
78
     PickType pickType = PickType.all,
79
     BadgeDelegate badgeDelegate = const DefaultBadgeDelegate(),
79
     BadgeDelegate badgeDelegate = const DefaultBadgeDelegate(),
80
-    List<AssetPathEntity> photoList,
80
+    List<AssetPathEntity> photoPathList,
81
   }) {
81
   }) {
82
     assert(provider != null, "provider must be not null");
82
     assert(provider != null, "provider must be not null");
83
     assert(context != null, "context must be not null");
83
     assert(context != null, "context must be not null");
114
       context,
114
       context,
115
       options,
115
       options,
116
       provider,
116
       provider,
117
-      photoList,
117
+      photoPathList,
118
     );
118
     );
119
   }
119
   }
120
 
120
 

+ 1
- 1
lib/src/provider/i18n_provider.dart View File

102
 
102
 
103
   @override
103
   @override
104
   String getAllGalleryText(Options options) {
104
   String getAllGalleryText(Options options) {
105
-    return "all";
105
+    return "Recent";
106
   }
106
   }
107
 
107
 
108
   @override
108
   @override

+ 19
- 2
lib/src/ui/dialog/change_gallery_dialog.dart View File

1
 import 'package:flutter/material.dart';
1
 import 'package:flutter/material.dart';
2
+import 'package:photo/src/entity/options.dart';
3
+import 'package:photo/src/provider/i18n_provider.dart';
2
 import 'package:photo_manager/photo_manager.dart';
4
 import 'package:photo_manager/photo_manager.dart';
3
 
5
 
4
 class ChangeGalleryDialog extends StatefulWidget {
6
 class ChangeGalleryDialog extends StatefulWidget {
5
   final List<AssetPathEntity> galleryList;
7
   final List<AssetPathEntity> galleryList;
8
+  final I18nProvider i18n;
9
+  final Options options;
6
 
10
 
7
-  const ChangeGalleryDialog({Key key, this.galleryList}) : super(key: key);
11
+  const ChangeGalleryDialog({
12
+    Key key,
13
+    this.galleryList,
14
+    this.i18n,
15
+    this.options,
16
+  }) : super(key: key);
8
 
17
 
9
   @override
18
   @override
10
   _ChangeGalleryDialogState createState() => _ChangeGalleryDialogState();
19
   _ChangeGalleryDialogState createState() => _ChangeGalleryDialogState();
23
 
32
 
24
   Widget _buildItem(BuildContext context, int index) {
33
   Widget _buildItem(BuildContext context, int index) {
25
     var entity = widget.galleryList[index];
34
     var entity = widget.galleryList[index];
35
+    String text;
36
+
37
+    if (entity.isAll) {
38
+      text = widget.i18n?.getAllGalleryText(widget.options);
39
+    }
40
+
41
+    text = text ?? entity.name;
42
+
26
     return FlatButton(
43
     return FlatButton(
27
       child: ListTile(
44
       child: ListTile(
28
-        title: Text(entity.name),
45
+        title: Text(text),
29
       ),
46
       ),
30
       onPressed: () {
47
       onPressed: () {
31
         Navigator.pop(context, entity);
48
         Navigator.pop(context, entity);

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

55
     _currentPath = value;
55
     _currentPath = value;
56
   }
56
   }
57
 
57
 
58
+  String get currentGalleryName {
59
+    if (currentPath.isAll) {
60
+      return i18nProvider.getAllGalleryText(options);
61
+    }
62
+    return currentPath.name;
63
+  }
64
+
58
   GlobalKey scaffoldKey;
65
   GlobalKey scaffoldKey;
59
   ScrollController scrollController;
66
   ScrollController scrollController;
60
 
67
 
111
             key: scaffoldKey,
118
             key: scaffoldKey,
112
             provider: i18nProvider,
119
             provider: i18nProvider,
113
             options: options,
120
             options: options,
114
-            galleryName: currentPath.name,
121
+            galleryName: currentGalleryName,
115
             onGalleryChange: _onGalleryChange,
122
             onGalleryChange: _onGalleryChange,
116
             onTapPreview: selectedList.isEmpty ? null : _onTapPreview,
123
             onTapPreview: selectedList.isEmpty ? null : _onTapPreview,
117
             selectedProvider: this,
124
             selectedProvider: this,
527
       context: context,
534
       context: context,
528
       builder: (ctx) => ChangeGalleryDialog(
535
       builder: (ctx) => ChangeGalleryDialog(
529
             galleryList: widget.galleryListProvider.galleryPathList,
536
             galleryList: widget.galleryListProvider.galleryPathList,
537
+            i18n: i18nProvider,
538
+            options: options,
530
           ),
539
           ),
531
     );
540
     );
532
 
541