lucky1213 4 years ago
parent
commit
8b77aa44fc
5 changed files with 58 additions and 44 deletions
  1. 9
    6
      lib/photo.dart
  2. 9
    9
      lib/src/entity/_theme.dart
  3. 1
    1
      lib/src/entity/options.dart
  4. 38
    27
      lib/src/ui/page/photo_list_page.dart
  5. 1
    1
      pubspec.yaml

+ 9
- 6
lib/photo.dart View File

26
     show I18NCustomProvider, I18nProvider, CNProvider, ENProvider;
26
     show I18NCustomProvider, I18nProvider, CNProvider, ENProvider;
27
 export 'package:photo/src/entity/options.dart' show PickType;
27
 export 'package:photo/src/entity/options.dart' show PickType;
28
 export 'package:photo/src/delegate/badge_delegate.dart';
28
 export 'package:photo/src/delegate/badge_delegate.dart';
29
+export 'package:photo/src/entity/_theme.dart';
29
 
30
 
30
 class PhotoPicker {
31
 class PhotoPicker {
31
   static PhotoPicker _instance;
32
   static PhotoPicker _instance;
75
     int maxSelected = 9,
76
     int maxSelected = 9,
76
     double padding = 1,
77
     double padding = 1,
77
     double itemRadio = 1.0,
78
     double itemRadio = 1.0,
78
-    int thumbSize = 64,
79
+    int thumbSize = 180,
80
+    PhotoTheme theme,
79
     I18nProvider provider = I18nProvider.chinese,
81
     I18nProvider provider = I18nProvider.chinese,
80
     SortDelegate sortDelegate,
82
     SortDelegate sortDelegate,
81
     LoadingDelegate loadingDelegate,
83
     LoadingDelegate loadingDelegate,
96
       maxSelected: maxSelected,
98
       maxSelected: maxSelected,
97
       itemRadio: itemRadio,
99
       itemRadio: itemRadio,
98
       padding: padding,
100
       padding: padding,
99
-      theme: PhotoTheme.fallback(context),
101
+      theme: theme ?? PhotoTheme.fallback(context),
100
       thumbSize: thumbSize,
102
       thumbSize: thumbSize,
101
       sortDelegate: sortDelegate,
103
       sortDelegate: sortDelegate,
102
       checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(),
104
       checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(),
135
   static Widget buildGallery({
137
   static Widget buildGallery({
136
     @required BuildContext context,
138
     @required BuildContext context,
137
     double padding = 1,
139
     double padding = 1,
138
-    @required double itemHeight,
140
+    double itemHeight,
139
     @required double itemWidth,
141
     @required double itemWidth,
140
-    int thumbSize = 64,
142
+    int thumbSize = 180,
143
+    PhotoTheme theme,
141
     I18nProvider provider = I18nProvider.chinese,
144
     I18nProvider provider = I18nProvider.chinese,
142
     SortDelegate sortDelegate,
145
     SortDelegate sortDelegate,
143
     LoadingDelegate loadingDelegate,
146
     LoadingDelegate loadingDelegate,
154
       padding: padding,
157
       padding: padding,
155
       itemHeight: itemHeight,
158
       itemHeight: itemHeight,
156
       itemWidth: itemWidth,
159
       itemWidth: itemWidth,
157
-      theme: PhotoTheme.fallback(context),
160
+      theme: theme ?? PhotoTheme.fallback(context),
158
       thumbSize: thumbSize,
161
       thumbSize: thumbSize,
159
       sortDelegate: sortDelegate,
162
       sortDelegate: sortDelegate,
160
       checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(),
163
       checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(),
212
           ),
215
           ),
213
           child: PhotoMainPage(
216
           child: PhotoMainPage(
214
             onClose: (List<AssetEntity> value) {
217
             onClose: (List<AssetEntity> value) {
215
-              Navigator.pop(context, value);
218
+              Navigator.pop(ctx, value);
216
             },
219
             },
217
             options: options,
220
             options: options,
218
             photoList: photoList,
221
             photoList: photoList,

+ 9
- 9
lib/src/entity/_theme.dart View File

14
 
14
 
15
   factory PhotoTheme.fallback(BuildContext context) {
15
   factory PhotoTheme.fallback(BuildContext context) {
16
     final theme = Theme.of(context);
16
     final theme = Theme.of(context);
17
-    return PhotoTheme._(
18
-      primaryColor: theme.colorScheme?.primary ?? Color(0xFF01AAFF),
19
-      onPrimaryColor: theme.colorScheme?.onPrimary ?? Color(0xFFFFFFFF),
20
-      surfaceColor: theme.colorScheme?.surface ?? (theme.brightness == Brightness.light ? Color(0xFFFFFFFF) : Color(0xFF282828)),
21
-      onSurfaceColor: theme.colorScheme?.onSurface ?? (theme.brightness == Brightness.light ? Color(0xFF8C8C8C) : Color(0xFF696969)),
22
-      backgroundColor: theme.colorScheme?.background ?? (theme.brightness == Brightness.light ? Color(0xFFF8F8F8) : Color(0xFF1F1F1F)),
23
-      onBackgroundColor: theme.colorScheme?.onBackground ?? Color(0xFF8C8C8C),
17
+    return PhotoTheme(
18
+      primaryColor: Color(0xFF01AAFF),
19
+      onPrimaryColor: Color(0xFFFFFFFF),
20
+      surfaceColor: theme.brightness == Brightness.light ? Color(0xFFFFFFFF) : Color(0xFF282828),
21
+      onSurfaceColor: theme.brightness == Brightness.light ? Color(0xFF8C8C8C) : Color(0xFF696969),
22
+      backgroundColor: theme.brightness == Brightness.light ? Color(0xFFF8F8F8) : Color(0xFF1F1F1F),
23
+      onBackgroundColor: Color(0xFF8C8C8C),
24
       dividerColor: theme.dividerColor ?? (theme.brightness == Brightness.light ? Color(0xFFF2F2F2) : Color(0xFF3B3B3B)),
24
       dividerColor: theme.dividerColor ?? (theme.brightness == Brightness.light ? Color(0xFFF2F2F2) : Color(0xFF3B3B3B)),
25
       disableColor: theme.disabledColor,
25
       disableColor: theme.disabledColor,
26
       unselectedColor: theme.unselectedWidgetColor ?? (theme.brightness == Brightness.light ? Color(0xFFBFBFBF) : Color(0xFF696969)),
26
       unselectedColor: theme.unselectedWidgetColor ?? (theme.brightness == Brightness.light ? Color(0xFFBFBFBF) : Color(0xFF696969)),
32
     );
32
     );
33
   }
33
   }
34
 
34
 
35
-  PhotoTheme._({
35
+  PhotoTheme({
36
     @required this.primaryColor,
36
     @required this.primaryColor,
37
     @required this.onPrimaryColor,
37
     @required this.onPrimaryColor,
38
     @required this.surfaceColor,
38
     @required this.surfaceColor,
57
     Color unselectedColor,
57
     Color unselectedColor,
58
     TextStyle textStyle,
58
     TextStyle textStyle,
59
   }) {
59
   }) {
60
-    return PhotoTheme._(
60
+    return PhotoTheme(
61
       primaryColor: primaryColor ?? this.primaryColor,
61
       primaryColor: primaryColor ?? this.primaryColor,
62
       onPrimaryColor: onPrimaryColor ?? this.onPrimaryColor,
62
       onPrimaryColor: onPrimaryColor ?? this.onPrimaryColor,
63
       surfaceColor: surfaceColor ?? this.surfaceColor,
63
       surfaceColor: surfaceColor ?? this.surfaceColor,

+ 1
- 1
lib/src/entity/options.dart View File

52
   final Axis scrollDirection;
52
   final Axis scrollDirection;
53
 
53
 
54
   const ListOptions({
54
   const ListOptions({
55
-    this.itemHeight,
55
+    this.itemHeight = double.infinity,
56
     this.itemWidth,
56
     this.itemWidth,
57
     this.scrollDirection = Axis.horizontal,
57
     this.scrollDirection = Axis.horizontal,
58
     int maxSelected,
58
     int maxSelected,

+ 38
- 27
lib/src/ui/page/photo_list_page.dart View File

11
 import 'photo_main_page.dart';
11
 import 'photo_main_page.dart';
12
 import 'photo_preview_page.dart';
12
 import 'photo_preview_page.dart';
13
 
13
 
14
-
15
 class PhotoListPage extends StatefulWidget {
14
 class PhotoListPage extends StatefulWidget {
16
   final ValueChanged<List<AssetEntity>> onSelected;
15
   final ValueChanged<List<AssetEntity>> onSelected;
17
   final ListOptions options;
16
   final ListOptions options;
28
 
27
 
29
 class _PhotoListPageState extends State<PhotoListPage>
28
 class _PhotoListPageState extends State<PhotoListPage>
30
     with SelectedProvider, GalleryListProvider, WidgetsBindingObserver {
29
     with SelectedProvider, GalleryListProvider, WidgetsBindingObserver {
31
-  PhotoProvider get config => Provider.of<PhotoProvider>(context, listen: false);
30
+  PhotoProvider get config =>
31
+      Provider.of<PhotoProvider>(context, listen: false);
32
   ListOptions get options => widget.options;
32
   ListOptions get options => widget.options;
33
   I18nProvider get i18nProvider => config.provider;
33
   I18nProvider get i18nProvider => config.provider;
34
   AssetProvider get assetProvider => config.assetProvider;
34
   AssetProvider get assetProvider => config.assetProvider;
42
   bool isPushed = false;
42
   bool isPushed = false;
43
 
43
 
44
   // Throttle _changeThrottle;
44
   // Throttle _changeThrottle;
45
-  
45
+
46
   @override
46
   @override
47
   void initState() {
47
   void initState() {
48
     super.initState();
48
     super.initState();
91
     List<AssetPathEntity> pathList;
91
     List<AssetPathEntity> pathList;
92
     switch (options.pickType) {
92
     switch (options.pickType) {
93
       case PickType.onlyImage:
93
       case PickType.onlyImage:
94
-        pathList = await PhotoManager.getAssetPathList(type: RequestType.image, onlyAll: true);
94
+        pathList = await PhotoManager.getAssetPathList(
95
+            type: RequestType.image, onlyAll: true);
95
         break;
96
         break;
96
       case PickType.onlyVideo:
97
       case PickType.onlyVideo:
97
-        pathList = await PhotoManager.getAssetPathList(type: RequestType.video, onlyAll: true);
98
+        pathList = await PhotoManager.getAssetPathList(
99
+            type: RequestType.video, onlyAll: true);
98
         break;
100
         break;
99
       default:
101
       default:
100
-        pathList = await PhotoManager.getAssetPathList(type: RequestType.image | RequestType.video, onlyAll: true);
102
+        pathList = await PhotoManager.getAssetPathList(
103
+            type: RequestType.image | RequestType.video, onlyAll: true);
101
     }
104
     }
102
 
105
 
103
     return _onRefreshAssetPathList(pathList);
106
     return _onRefreshAssetPathList(pathList);
149
       SnackBar(
152
       SnackBar(
150
         content: Text(
153
         content: Text(
151
           msg,
154
           msg,
152
-          style: options.theme.textStyle.copyWith(color: options.theme.onPrimaryColor),
155
+          style: options.theme.textStyle
156
+              .copyWith(color: options.theme.onPrimaryColor),
153
         ),
157
         ),
154
         duration: Duration(milliseconds: 1500),
158
         duration: Duration(milliseconds: 1500),
155
         backgroundColor: options.theme.primaryColor.withOpacity(0.7),
159
         backgroundColor: options.theme.primaryColor.withOpacity(0.7),
189
     }
193
     }
190
 
194
 
191
     var data = list[index];
195
     var data = list[index];
192
-    return RepaintBoundary(
193
-      child: GestureDetector(
194
-        onTap: () => _onItemClick(data, index),
195
-        child: Stack(
196
-          children: <Widget>[
197
-            ImageItem(
198
-              entity: data,
199
-              themeColor: options.theme.primaryColor,
200
-              size: options.thumbSize,
201
-              loadingDelegate: options.loadingDelegate,
202
-              badgeDelegate: options.badgeDelegate,
203
-            ),
204
-            _buildMask(containsEntity(data)),
205
-            _buildSelected(data),
206
-          ],
196
+    return Padding(
197
+      padding: EdgeInsets.only(left: index != 0 ? options.padding : 0),
198
+      child: RepaintBoundary(
199
+        child: GestureDetector(
200
+          onTap: () => _onItemClick(data, index),
201
+          child: Stack(
202
+            children: <Widget>[
203
+              ImageItem(
204
+                entity: data,
205
+                themeColor: options.theme.primaryColor,
206
+                size: options.thumbSize,
207
+                loadingDelegate: options.loadingDelegate,
208
+                badgeDelegate: options.badgeDelegate,
209
+              ),
210
+              _buildMask(containsEntity(data)),
211
+              _buildSelected(data),
212
+            ],
213
+          ),
207
         ),
214
         ),
208
       ),
215
       ),
209
     );
216
     );
247
   Widget _buildText(AssetEntity entity) {
254
   Widget _buildText(AssetEntity entity) {
248
     var isSelected = containsEntity(entity);
255
     var isSelected = containsEntity(entity);
249
     Widget child;
256
     Widget child;
250
-    BoxDecoration decoration = BoxDecoration(borderRadius: BorderRadius.circular(1.0),);
257
+    BoxDecoration decoration = BoxDecoration(
258
+      borderRadius: BorderRadius.circular(1.0),
259
+    );
251
     if (isSelected) {
260
     if (isSelected) {
252
       child = Text(
261
       child = Text(
253
         (indexOfSelected(entity) + 1).toString(),
262
         (indexOfSelected(entity) + 1).toString(),
259
       );
268
       );
260
       decoration = decoration.copyWith(color: options.theme.primaryColor);
269
       decoration = decoration.copyWith(color: options.theme.primaryColor);
261
     } else {
270
     } else {
262
-      decoration = decoration.copyWith(border: Border.all(
263
-        color: options.theme.onPrimaryColor.withAlpha(200),
264
-      ),);
271
+      decoration = decoration.copyWith(
272
+        border: Border.all(
273
+          color: options.theme.onPrimaryColor.withAlpha(200),
274
+        ),
275
+      );
265
     }
276
     }
266
     return Padding(
277
     return Padding(
267
       padding: const EdgeInsets.all(8.0),
278
       padding: const EdgeInsets.all(8.0),
341
       ),
352
       ),
342
     );
353
     );
343
   }
354
   }
344
-}
355
+}

+ 1
- 1
pubspec.yaml View File

1
 name: photo
1
 name: photo
2
 description: image picker, multi picker support video/icloud asset, use flutter as ui, if you want to build custom ui, you just use photo_manager.
2
 description: image picker, multi picker support video/icloud asset, use flutter as ui, if you want to build custom ui, you just use photo_manager.
3
-version: 0.5.0-dev.1
3
+version: 0.5.0-dev.2
4
 author: caijinglong<cjl_spy@163.com>
4
 author: caijinglong<cjl_spy@163.com>
5
 homepage: https://github.com/CaiJingLong/flutter_photo
5
 homepage: https://github.com/CaiJingLong/flutter_photo
6
 
6