Browse Source

add album cover && i18n

lucky1213 4 years ago
parent
commit
4e482c727c

+ 1
- 0
example/ios/Flutter/.last_build_id View File

1
+e66d98e32fcb326d739aa957c5133ebc

+ 0
- 2
example/ios/Runner.xcodeproj/project.pbxproj View File

316
 /* Begin XCBuildConfiguration section */
316
 /* Begin XCBuildConfiguration section */
317
 		97C147031CF9000F007C117D /* Debug */ = {
317
 		97C147031CF9000F007C117D /* Debug */ = {
318
 			isa = XCBuildConfiguration;
318
 			isa = XCBuildConfiguration;
319
-			baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
320
 			buildSettings = {
319
 			buildSettings = {
321
 				ALWAYS_SEARCH_USER_PATHS = NO;
320
 				ALWAYS_SEARCH_USER_PATHS = NO;
322
 				CLANG_ANALYZER_NONNULL = YES;
321
 				CLANG_ANALYZER_NONNULL = YES;
370
 		};
369
 		};
371
 		97C147041CF9000F007C117D /* Release */ = {
370
 		97C147041CF9000F007C117D /* Release */ = {
372
 			isa = XCBuildConfiguration;
371
 			isa = XCBuildConfiguration;
373
-			baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
374
 			buildSettings = {
372
 			buildSettings = {
375
 				ALWAYS_SEARCH_USER_PATHS = NO;
373
 				ALWAYS_SEARCH_USER_PATHS = NO;
376
 				CLANG_ANALYZER_NONNULL = YES;
374
 				CLANG_ANALYZER_NONNULL = YES;

+ 6
- 6
example/lib/main.dart View File

161
     /// context is required, other params is optional.
161
     /// context is required, other params is optional.
162
     List<AssetPathEntity> pathList2 = await PhotoManager.getAssetPathList(
162
     List<AssetPathEntity> pathList2 = await PhotoManager.getAssetPathList(
163
         hasAll: true, type: RequestType.image,);
163
         hasAll: true, type: RequestType.image,);
164
-    List<AssetEntity> imgList = await PhotoPicker.pickAsset(
164
+    PickedEntity entity = await PhotoPicker.pickAsset(
165
       context: context,
165
       context: context,
166
       padding: 4.0,
166
       padding: 4.0,
167
       itemRadio: 1,
167
       itemRadio: 1,
168
-      maxSelected: 8,
169
-      provider: I18nProvider.chinese,
168
+      maxSelected: 2,
169
+      provider: I18nProvider.english,
170
       rowCount: 4,
170
       rowCount: 4,
171
       thumbSize: 150,
171
       thumbSize: 150,
172
       sortDelegate: SortDelegate.common,
172
       sortDelegate: SortDelegate.common,
174
       photoPathList: pathList2,
174
       photoPathList: pathList2,
175
     );
175
     );
176
 
176
 
177
-    if (imgList == null || imgList.isEmpty) {
177
+    if (entity == null || entity.asset.isEmpty) {
178
       showToast("No pick item.");
178
       showToast("No pick item.");
179
       return;
179
       return;
180
     } else {
180
     } else {
181
       List<String> r = [];
181
       List<String> r = [];
182
-      for (var e in imgList) {
182
+      for (var e in entity.asset) {
183
         var file = await e.file;
183
         var file = await e.file;
184
         r.add(file.absolute.path);
184
         r.add(file.absolute.path);
185
       }
185
       }
186
       currentSelected = r.join("\n\n");
186
       currentSelected = r.join("\n\n");
187
 
187
 
188
       List<AssetEntity> preview = [];
188
       List<AssetEntity> preview = [];
189
-      preview.addAll(imgList);
189
+      preview.addAll(entity.asset);
190
       Navigator.push(context,
190
       Navigator.push(context,
191
           MaterialPageRoute(builder: (_) => PreviewPage(list: preview)));
191
           MaterialPageRoute(builder: (_) => PreviewPage(list: preview)));
192
     }
192
     }

+ 3
- 3
example/lib/picked_example.dart View File

35
   }
35
   }
36
 
36
 
37
   void _pickAsset() async {
37
   void _pickAsset() async {
38
-    final result = await PhotoPicker.pickAsset(
38
+    final entity = await PhotoPicker.pickAsset(
39
       context: context,
39
       context: context,
40
       pickedAssetList: picked,
40
       pickedAssetList: picked,
41
     );
41
     );
42
-    if (result != null && result.isNotEmpty) {
42
+    if (entity != null && entity.asset.isNotEmpty) {
43
       picked.clear();
43
       picked.clear();
44
-      picked.addAll(result);
44
+      picked.addAll(entity.asset);
45
       setState(() {});
45
       setState(() {});
46
     }
46
     }
47
   }
47
   }

+ 15
- 3
lib/src/provider/i18n_provider.dart View File

6
 
6
 
7
   String getTitleText(Options options);
7
   String getTitleText(Options options);
8
 
8
 
9
+  String getCancelText(Options options);
10
+
9
   String getSureText(Options options, int currentCount);
11
   String getSureText(Options options, int currentCount);
10
 
12
 
11
   String getPreviewText(Options options, SelectedProvider selectedProvider);
13
   String getPreviewText(Options options, SelectedProvider selectedProvider);
42
     return "预览(${selectedProvider.selectedCount})";
44
     return "预览(${selectedProvider.selectedCount})";
43
   }
45
   }
44
 
46
 
47
+  @override
48
+  String getCancelText(Options options) {
49
+    return "取消";
50
+  }
51
+
45
   @override
52
   @override
46
   String getSureText(Options options, int currentCount) {
53
   String getSureText(Options options, int currentCount) {
47
     return "确定($currentCount/${options.maxSelected})";
54
     return "确定($currentCount/${options.maxSelected})";
92
     return "Preview (${selectedProvider.selectedCount})";
99
     return "Preview (${selectedProvider.selectedCount})";
93
   }
100
   }
94
 
101
 
102
+  @override
103
+  String getCancelText(Options options) {
104
+    return "Cancel";
105
+  }
106
+
95
   @override
107
   @override
96
   String getSureText(Options options, int currentCount) {
108
   String getSureText(Options options, int currentCount) {
97
-    return "Save ($currentCount/${options.maxSelected})";
109
+    return "Confirm ($currentCount/${options.maxSelected})";
98
   }
110
   }
99
 
111
 
100
   @override
112
   @override
104
 
116
 
105
   @override
117
   @override
106
   String getFullImageText(Options options) {
118
   String getFullImageText(Options options) {
107
-    return "Full Image";
119
+    return "Full image";
108
   }
120
   }
109
 
121
 
110
   @override
122
   @override
114
 
126
 
115
   @override
127
   @override
116
   String getAllGalleryText(Options options) {
128
   String getAllGalleryText(Options options) {
117
-    return "Recent";
129
+    return "All";
118
   }
130
   }
119
 
131
 
120
   @override
132
   @override

+ 72
- 36
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';
2
 import 'package:photo/src/entity/options.dart';
3
 import 'package:photo/src/provider/i18n_provider.dart';
3
 import 'package:photo/src/provider/i18n_provider.dart';
4
+import 'package:photo/src/ui/page/photo_main_page.dart';
4
 import 'package:photo_manager/photo_manager.dart';
5
 import 'package:photo_manager/photo_manager.dart';
5
 
6
 
6
 class ChangeGalleryDialog extends StatefulWidget {
7
 class ChangeGalleryDialog extends StatefulWidget {
7
-
8
   final ValueChanged<AssetPathEntity> onGalleryChange;
8
   final ValueChanged<AssetPathEntity> onGalleryChange;
9
   final List<AssetPathEntity> galleryList;
9
   final List<AssetPathEntity> galleryList;
10
   final I18nProvider i18n;
10
   final I18nProvider i18n;
25
 }
25
 }
26
 
26
 
27
 class _ChangeGalleryDialogState extends State<ChangeGalleryDialog> {
27
 class _ChangeGalleryDialogState extends State<ChangeGalleryDialog> {
28
-      
29
   @override
28
   @override
30
   Widget build(BuildContext context) {
29
   Widget build(BuildContext context) {
31
     return Container(
30
     return Container(
42
     );
41
     );
43
   }
42
   }
44
 
43
 
44
+  Future<AssetEntity> getCoverForGallery(AssetPathEntity gallery) async {
45
+    List<AssetEntity> assets =
46
+        await gallery.getAssetListRange(start: 0, end: 1);
47
+    if (assets.isNotEmpty) {
48
+      return assets[0];
49
+    }
50
+    return null;
51
+  }
52
+
45
   Widget _buildItem(BuildContext context, int index) {
53
   Widget _buildItem(BuildContext context, int index) {
46
     var entity = widget.galleryList[index];
54
     var entity = widget.galleryList[index];
47
     String text;
55
     String text;
58
         padding: EdgeInsets.symmetric(vertical: 12),
66
         padding: EdgeInsets.symmetric(vertical: 12),
59
         decoration: BoxDecoration(
67
         decoration: BoxDecoration(
60
           border: Border(
68
           border: Border(
61
-            top: index == 0 ? BorderSide.none : BorderSide(color: widget.options.theme.dividerColor, width: 1),
69
+            top: index == 0
70
+                ? BorderSide.none
71
+                : BorderSide(
72
+                    color: widget.options.theme.dividerColor, width: 1),
62
           ),
73
           ),
63
         ),
74
         ),
64
         child: Row(
75
         child: Row(
65
           children: [
76
           children: [
66
             // ImageItem(),
77
             // ImageItem(),
67
-            Container(
78
+            SizedBox(
68
               width: 40,
79
               width: 40,
69
               height: 40,
80
               height: 40,
70
-              color: Colors.black,
81
+              child: FutureBuilder(
82
+                future: getCoverForGallery(entity),
83
+                initialData: null,
84
+                builder: (BuildContext context,
85
+                    AsyncSnapshot<AssetEntity> snapshot) {
86
+                  if (snapshot.data != null) {
87
+                    return ImageItem(
88
+                      entity: snapshot.data,
89
+                      size: widget.options.thumbSize,
90
+                      themeColor: widget.options.theme.primaryColor,
91
+                      loadingDelegate: widget.options.loadingDelegate,
92
+                      badgeDelegate: widget.options.badgeDelegate,
93
+                    );
94
+                  } else {
95
+                    return Container();
96
+                  }
97
+                },
98
+              ),
99
+            ),
100
+            SizedBox(
101
+              width: 16,
71
             ),
102
             ),
72
-            SizedBox(width: 16,),
73
             Expanded(
103
             Expanded(
74
-              child: Row(
75
-                children: [
76
-                  Expanded(
77
-                    child: Row(
78
-                      children: <Widget>[
79
-                        Text('$text ', style: widget.options.theme.textStyle,),
80
-                        Text('(${entity.assetCount})', style: widget.options.theme.textStyle.copyWith(fontSize: 14),),
81
-                      ],
82
-                    ),
104
+                child: Row(
105
+              children: [
106
+                Expanded(
107
+                  child: Row(
108
+                    children: <Widget>[
109
+                      Text(
110
+                        '$text ',
111
+                        style: widget.options.theme.textStyle,
112
+                      ),
113
+                      Text(
114
+                        '(${entity.assetCount})',
115
+                        style: widget.options.theme.textStyle
116
+                            .copyWith(fontSize: 14),
117
+                      ),
118
+                    ],
83
                   ),
119
                   ),
84
-                  if (widget.current.id == entity.id)
120
+                ),
121
+                if (widget.current.id == entity.id)
85
                   Icon(
122
                   Icon(
86
                     Icons.check_circle,
123
                     Icons.check_circle,
87
                     size: 20,
124
                     size: 20,
88
                     color: widget.options.theme.primaryColor,
125
                     color: widget.options.theme.primaryColor,
89
                   ),
126
                   ),
90
-                  // RichText(
91
-                  //   text: TextSpan(
92
-                  //     text: '$text ',
93
-                  //     style: widget.options.theme.textStyle.copyWith(
94
-                  //       height: 1.4,
95
-                  //     ),
96
-                  //     children: [
97
-                  //       TextSpan(
98
-                  //         text: '(${entity.assetCount})',
99
-                  //         style: widget.options.theme.textStyle.copyWith(
100
-                  //           fontSize: 14,
101
-                  //           height: 1.6,
102
-                  //         ),
103
-                  //       )
104
-                  //     ]
105
-                  //   ),
106
-                  // )
107
-                ],
108
-              )
109
-            ),
127
+                // RichText(
128
+                //   text: TextSpan(
129
+                //     text: '$text ',
130
+                //     style: widget.options.theme.textStyle.copyWith(
131
+                //       height: 1.4,
132
+                //     ),
133
+                //     children: [
134
+                //       TextSpan(
135
+                //         text: '(${entity.assetCount})',
136
+                //         style: widget.options.theme.textStyle.copyWith(
137
+                //           fontSize: 14,
138
+                //           height: 1.6,
139
+                //         ),
140
+                //       )
141
+                //     ]
142
+                //   ),
143
+                // )
144
+              ],
145
+            )),
110
           ],
146
           ],
111
         ),
147
         ),
112
       ),
148
       ),

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

160
       style: options.theme.textStyle,
160
       style: options.theme.textStyle,
161
       child: Scaffold(
161
       child: Scaffold(
162
         appBar: AppBar(
162
         appBar: AppBar(
163
+          titleSpacing: 0.0,
163
           backgroundColor: options.theme.surfaceColor,
164
           backgroundColor: options.theme.surfaceColor,
164
-          leading: IconButton(
165
-            icon: Text('取消', style: options.theme.textStyle),
166
-            onPressed: _cancel,
167
-          ),
165
+          automaticallyImplyLeading: false,
168
           centerTitle: true,
166
           centerTitle: true,
169
-          title: FlatButton(
170
-            padding: EdgeInsets.zero,
171
-            onPressed: _showGallerySelectDialog,
172
-            splashColor: Colors.transparent,
173
-            highlightColor: Colors.transparent,
174
-            child: Container(
175
-                alignment: Alignment.center,
176
-                height: 44.0,
177
-                padding: EdgeInsets.zero.copyWith(right: kToolbarHeight),
178
-                child: Row(
179
-                  mainAxisAlignment: MainAxisAlignment.center,
180
-                  children: [
181
-                    Text(
182
-                      currentGalleryName,
183
-                      style: options.theme.textStyle.apply(
184
-                        fontSizeDelta: 2.0,
185
-                        fontWeightDelta: 1,
186
-                      ),
187
-                    ),
188
-                    Container(
189
-                      width: 18,
190
-                      height: 18,
191
-                      margin: EdgeInsets.only(left: 8),
192
-                      decoration: ShapeDecoration(
193
-                          shape: CircleBorder(
194
-                        side: BorderSide(
195
-                            color: options.theme.onSurfaceColor, width: 1.5),
196
-                      )),
197
-                      child: AnimatedSwitcher(
198
-                        transitionBuilder: (child, animation) {
199
-                          final Tween<double> tween = overlayEntry != null
200
-                              ? Tween(begin: -0.25, end: 0.25)
201
-                              : Tween(begin: 0.25, end: 0.75);
202
-                          //var tween = Tween(begin: -0.5, end: 0.0);
203
-                          return RotationTransition(
204
-                              child: child, turns: tween.animate(animation));
205
-                        },
206
-                        duration: Duration(milliseconds: 200),
207
-                        reverseDuration: Duration(milliseconds: 0),
208
-                        child: Icon(Icons.chevron_left,
209
-                            key: ValueKey(overlayEntry == null ? 0 : 1),
210
-                            size: 14,
211
-                            color: options.theme.onSurfaceColor),
212
-                      ),
213
-                    ),
214
-                  ],
215
-                )),
167
+          title: Row(
168
+              mainAxisAlignment: MainAxisAlignment.start,
169
+              crossAxisAlignment: CrossAxisAlignment.center,
170
+              children: [
171
+                GestureDetector(
172
+                  behavior: HitTestBehavior.opaque,
173
+                  onTap: _cancel,
174
+                  child: Container(
175
+                    height: kToolbarHeight,
176
+                    padding: kTabLabelPadding,
177
+                    alignment: Alignment.center,
178
+                    child: Text(i18nProvider.getCancelText(options), style: options.theme.textStyle),
179
+                  ),
180
+                ),
181
+                Expanded(
182
+                  child: FlatButton(
183
+                    padding: EdgeInsets.zero,
184
+                    onPressed: _showGallerySelectDialog,
185
+                    splashColor: Colors.transparent,
186
+                    highlightColor: Colors.transparent,
187
+                    child: Container(
188
+                        alignment: Alignment.center,
189
+                        height: 44.0,
190
+                        child: Row(
191
+                          mainAxisAlignment: MainAxisAlignment.center,
192
+                          children: [
193
+                            Text(
194
+                              currentGalleryName,
195
+                              style: options.theme.textStyle.apply(
196
+                                fontSizeDelta: 2.0,
197
+                                fontWeightDelta: 1,
198
+                              ),
199
+                            ),
200
+                            Container(
201
+                              width: 18,
202
+                              height: 18,
203
+                              margin: EdgeInsets.only(left: 8),
204
+                              decoration: ShapeDecoration(
205
+                                  shape: CircleBorder(
206
+                                side: BorderSide(
207
+                                    color: options.theme.onSurfaceColor,
208
+                                    width: 1.5),
209
+                              )),
210
+                              child: AnimatedSwitcher(
211
+                                transitionBuilder: (child, animation) {
212
+                                  final Tween<double> tween = overlayEntry != null
213
+                                      ? Tween(begin: -0.25, end: 0.25)
214
+                                      : Tween(begin: 0.25, end: 0.75);
215
+                                  //var tween = Tween(begin: -0.5, end: 0.0);
216
+                                  return RotationTransition(
217
+                                      child: child,
218
+                                      turns: tween.animate(animation));
219
+                                },
220
+                                duration: Duration(milliseconds: 200),
221
+                                reverseDuration: Duration(milliseconds: 0),
222
+                                child: Icon(Icons.chevron_left,
223
+                                    key: ValueKey(overlayEntry == null ? 0 : 1),
224
+                                    size: 14,
225
+                                    color: options.theme.onSurfaceColor),
226
+                              ),
227
+                            ),
228
+                          ],
229
+                        )),
230
+                  ),
231
+                ),
232
+                Container(
233
+                  height: kToolbarHeight,
234
+                  padding: kTabLabelPadding,
235
+                  alignment: Alignment.center,
236
+                  child: Text(i18nProvider.getCancelText(options), style: options.theme.textStyle.copyWith(
237
+                    color: Colors.transparent,
238
+                  )),
239
+                ),
240
+              ],
216
           ),
241
           ),
217
         ),
242
         ),
218
         body: _buildBody(),
243
         body: _buildBody(),
267
               .copyWith(color: options.theme.onPrimaryColor),
292
               .copyWith(color: options.theme.onPrimaryColor),
268
         ),
293
         ),
269
         duration: Duration(milliseconds: 1500),
294
         duration: Duration(milliseconds: 1500),
270
-        backgroundColor: options.theme.primaryColor.withOpacity(0.7),
295
+        backgroundColor: options.theme.primaryColor,
271
       ),
296
       ),
272
     );
297
     );
273
   }
298
   }