lucky1213 4 år sedan
förälder
incheckning
8b77aa44fc
5 ändrade filer med 58 tillägg och 44 borttagningar
  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 Visa fil

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

+ 9
- 9
lib/src/entity/_theme.dart Visa fil

@@ -14,13 +14,13 @@ class PhotoTheme {
14 14
 
15 15
   factory PhotoTheme.fallback(BuildContext context) {
16 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 24
       dividerColor: theme.dividerColor ?? (theme.brightness == Brightness.light ? Color(0xFFF2F2F2) : Color(0xFF3B3B3B)),
25 25
       disableColor: theme.disabledColor,
26 26
       unselectedColor: theme.unselectedWidgetColor ?? (theme.brightness == Brightness.light ? Color(0xFFBFBFBF) : Color(0xFF696969)),
@@ -32,7 +32,7 @@ class PhotoTheme {
32 32
     );
33 33
   }
34 34
 
35
-  PhotoTheme._({
35
+  PhotoTheme({
36 36
     @required this.primaryColor,
37 37
     @required this.onPrimaryColor,
38 38
     @required this.surfaceColor,
@@ -57,7 +57,7 @@ class PhotoTheme {
57 57
     Color unselectedColor,
58 58
     TextStyle textStyle,
59 59
   }) {
60
-    return PhotoTheme._(
60
+    return PhotoTheme(
61 61
       primaryColor: primaryColor ?? this.primaryColor,
62 62
       onPrimaryColor: onPrimaryColor ?? this.onPrimaryColor,
63 63
       surfaceColor: surfaceColor ?? this.surfaceColor,

+ 1
- 1
lib/src/entity/options.dart Visa fil

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

+ 38
- 27
lib/src/ui/page/photo_list_page.dart Visa fil

@@ -11,7 +11,6 @@ import 'package:provider/provider.dart';
11 11
 import 'photo_main_page.dart';
12 12
 import 'photo_preview_page.dart';
13 13
 
14
-
15 14
 class PhotoListPage extends StatefulWidget {
16 15
   final ValueChanged<List<AssetEntity>> onSelected;
17 16
   final ListOptions options;
@@ -28,7 +27,8 @@ class PhotoListPage extends StatefulWidget {
28 27
 
29 28
 class _PhotoListPageState extends State<PhotoListPage>
30 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 32
   ListOptions get options => widget.options;
33 33
   I18nProvider get i18nProvider => config.provider;
34 34
   AssetProvider get assetProvider => config.assetProvider;
@@ -42,7 +42,7 @@ class _PhotoListPageState extends State<PhotoListPage>
42 42
   bool isPushed = false;
43 43
 
44 44
   // Throttle _changeThrottle;
45
-  
45
+
46 46
   @override
47 47
   void initState() {
48 48
     super.initState();
@@ -91,13 +91,16 @@ class _PhotoListPageState extends State<PhotoListPage>
91 91
     List<AssetPathEntity> pathList;
92 92
     switch (options.pickType) {
93 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 96
         break;
96 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 100
         break;
99 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 106
     return _onRefreshAssetPathList(pathList);
@@ -149,7 +152,8 @@ class _PhotoListPageState extends State<PhotoListPage>
149 152
       SnackBar(
150 153
         content: Text(
151 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 158
         duration: Duration(milliseconds: 1500),
155 159
         backgroundColor: options.theme.primaryColor.withOpacity(0.7),
@@ -189,21 +193,24 @@ class _PhotoListPageState extends State<PhotoListPage>
189 193
     }
190 194
 
191 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,7 +254,9 @@ class _PhotoListPageState extends State<PhotoListPage>
247 254
   Widget _buildText(AssetEntity entity) {
248 255
     var isSelected = containsEntity(entity);
249 256
     Widget child;
250
-    BoxDecoration decoration = BoxDecoration(borderRadius: BorderRadius.circular(1.0),);
257
+    BoxDecoration decoration = BoxDecoration(
258
+      borderRadius: BorderRadius.circular(1.0),
259
+    );
251 260
     if (isSelected) {
252 261
       child = Text(
253 262
         (indexOfSelected(entity) + 1).toString(),
@@ -259,9 +268,11 @@ class _PhotoListPageState extends State<PhotoListPage>
259 268
       );
260 269
       decoration = decoration.copyWith(color: options.theme.primaryColor);
261 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 277
     return Padding(
267 278
       padding: const EdgeInsets.all(8.0),
@@ -341,4 +352,4 @@ class _PhotoListPageState extends State<PhotoListPage>
341 352
       ),
342 353
     );
343 354
   }
344
-}
355
+}

+ 1
- 1
pubspec.yaml Visa fil

@@ -1,6 +1,6 @@
1 1
 name: photo
2 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 4
 author: caijinglong<cjl_spy@163.com>
5 5
 homepage: https://github.com/CaiJingLong/flutter_photo
6 6