Explorar el Código

add album cover && i18n

lucky1213 hace 4 años
padre
commit
4e482c727c

+ 1
- 0
example/ios/Flutter/.last_build_id Ver fichero

@@ -0,0 +1 @@
1
+e66d98e32fcb326d739aa957c5133ebc

+ 0
- 2
example/ios/Runner.xcodeproj/project.pbxproj Ver fichero

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

+ 6
- 6
example/lib/main.dart Ver fichero

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

+ 3
- 3
example/lib/picked_example.dart Ver fichero

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

+ 15
- 3
lib/src/provider/i18n_provider.dart Ver fichero

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

+ 72
- 36
lib/src/ui/dialog/change_gallery_dialog.dart Ver fichero

@@ -1,10 +1,10 @@
1 1
 import 'package:flutter/material.dart';
2 2
 import 'package:photo/src/entity/options.dart';
3 3
 import 'package:photo/src/provider/i18n_provider.dart';
4
+import 'package:photo/src/ui/page/photo_main_page.dart';
4 5
 import 'package:photo_manager/photo_manager.dart';
5 6
 
6 7
 class ChangeGalleryDialog extends StatefulWidget {
7
-
8 8
   final ValueChanged<AssetPathEntity> onGalleryChange;
9 9
   final List<AssetPathEntity> galleryList;
10 10
   final I18nProvider i18n;
@@ -25,7 +25,6 @@ class ChangeGalleryDialog extends StatefulWidget {
25 25
 }
26 26
 
27 27
 class _ChangeGalleryDialogState extends State<ChangeGalleryDialog> {
28
-      
29 28
   @override
30 29
   Widget build(BuildContext context) {
31 30
     return Container(
@@ -42,6 +41,15 @@ class _ChangeGalleryDialogState extends State<ChangeGalleryDialog> {
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 53
   Widget _buildItem(BuildContext context, int index) {
46 54
     var entity = widget.galleryList[index];
47 55
     String text;
@@ -58,55 +66,83 @@ class _ChangeGalleryDialogState extends State<ChangeGalleryDialog> {
58 66
         padding: EdgeInsets.symmetric(vertical: 12),
59 67
         decoration: BoxDecoration(
60 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 75
         child: Row(
65 76
           children: [
66 77
             // ImageItem(),
67
-            Container(
78
+            SizedBox(
68 79
               width: 40,
69 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 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 122
                   Icon(
86 123
                     Icons.check_circle,
87 124
                     size: 20,
88 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 Ver fichero

@@ -160,59 +160,84 @@ class _PhotoMainPageState extends State<PhotoMainPage>
160 160
       style: options.theme.textStyle,
161 161
       child: Scaffold(
162 162
         appBar: AppBar(
163
+          titleSpacing: 0.0,
163 164
           backgroundColor: options.theme.surfaceColor,
164
-          leading: IconButton(
165
-            icon: Text('取消', style: options.theme.textStyle),
166
-            onPressed: _cancel,
167
-          ),
165
+          automaticallyImplyLeading: false,
168 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 243
         body: _buildBody(),
@@ -267,7 +292,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
267 292
               .copyWith(color: options.theme.onPrimaryColor),
268 293
         ),
269 294
         duration: Duration(milliseconds: 1500),
270
-        backgroundColor: options.theme.primaryColor.withOpacity(0.7),
295
+        backgroundColor: options.theme.primaryColor,
271 296
       ),
272 297
     );
273 298
   }