Sfoglia il codice sorgente

update for gallery name

Caijinglong 5 anni fa
parent
commit
4c5c716f9c

+ 2
- 2
README.md Vedi File

@@ -77,11 +77,11 @@ void pickAsset() async {
77 77
 
78 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 86
 You can use [photo_manager] package to get `List<AssetPathEntity>` and handle or cache.
87 87
 

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

@@ -30,63 +30,6 @@ class MyHomePage extends StatefulWidget {
30 30
 class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
31 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 33
   @override
91 34
   Widget buildBigImageLoading(
92 35
       BuildContext context, AssetEntity entity, Color themeColor) {
@@ -120,6 +63,12 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
120 63
     return new Scaffold(
121 64
       appBar: new AppBar(
122 65
         title: new Text(widget.title),
66
+        actions: <Widget>[
67
+          FlatButton(
68
+            child: Icon(Icons.image),
69
+            onPressed: _testPhotoListParams,
70
+          ),
71
+        ],
123 72
       ),
124 73
       body: Container(
125 74
         child: SingleChildScrollView(
@@ -152,6 +101,70 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
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 170
 class IconTextButton extends StatelessWidget {

+ 4
- 4
lib/photo.dart Vedi File

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

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

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

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

@@ -1,10 +1,19 @@
1 1
 import 'package:flutter/material.dart';
2
+import 'package:photo/src/entity/options.dart';
3
+import 'package:photo/src/provider/i18n_provider.dart';
2 4
 import 'package:photo_manager/photo_manager.dart';
3 5
 
4 6
 class ChangeGalleryDialog extends StatefulWidget {
5 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 18
   @override
10 19
   _ChangeGalleryDialogState createState() => _ChangeGalleryDialogState();
@@ -23,9 +32,17 @@ class _ChangeGalleryDialogState extends State<ChangeGalleryDialog> {
23 32
 
24 33
   Widget _buildItem(BuildContext context, int index) {
25 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 43
     return FlatButton(
27 44
       child: ListTile(
28
-        title: Text(entity.name),
45
+        title: Text(text),
29 46
       ),
30 47
       onPressed: () {
31 48
         Navigator.pop(context, entity);

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

@@ -55,6 +55,13 @@ class _PhotoMainPageState extends State<PhotoMainPage>
55 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 65
   GlobalKey scaffoldKey;
59 66
   ScrollController scrollController;
60 67
 
@@ -111,7 +118,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
111 118
             key: scaffoldKey,
112 119
             provider: i18nProvider,
113 120
             options: options,
114
-            galleryName: currentPath.name,
121
+            galleryName: currentGalleryName,
115 122
             onGalleryChange: _onGalleryChange,
116 123
             onTapPreview: selectedList.isEmpty ? null : _onTapPreview,
117 124
             selectedProvider: this,
@@ -527,6 +534,8 @@ class __BottomWidgetState extends State<_BottomWidget> {
527 534
       context: context,
528 535
       builder: (ctx) => ChangeGalleryDialog(
529 536
             galleryList: widget.galleryListProvider.galleryPathList,
537
+            i18n: i18nProvider,
538
+            options: options,
530 539
           ),
531 540
     );
532 541