lucky1213 4 anni fa
parent
commit
35370a6859
5 ha cambiato i file con 99 aggiunte e 12 eliminazioni
  1. 25
    4
      example/lib/main.dart
  2. 36
    0
      lib/photo.dart
  3. 11
    2
      lib/src/ui/page/photo_main_page.dart
  4. 26
    5
      pubspec.lock
  5. 1
    1
      pubspec.yaml

+ 25
- 4
example/lib/main.dart Vedi File

@@ -105,6 +105,11 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
105 105
                 text: "photo",
106 106
                 onTap: () => _pickAsset(PickType.onlyImage),
107 107
               ),
108
+              IconTextButton(
109
+                icon: Icons.photo,
110
+                text: "single photo",
111
+                onTap: () => _pickAsset(PickType.onlyImage, single: true),
112
+              ),
108 113
               IconTextButton(
109 114
                 icon: Icons.videocam,
110 115
                 text: "video",
@@ -162,22 +167,23 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
162 167
     _pickAsset(PickType.all, pathList: assetPathList);
163 168
   }
164 169
 
165
-  void _pickAsset(PickType type, {List<AssetPathEntity> pathList}) async {
170
+  void _pickAsset(PickType type, {List<AssetPathEntity> pathList, bool single = false}) async {
166 171
     /// context is required, other params is optional.
167 172
     /// context is required, other params is optional.
168 173
     /// context is required, other params is optional.
169 174
     List<AssetPathEntity> pathList2 = await PhotoManager.getAssetPathList(
170 175
         hasAll: true, type: RequestType.image,);
171
-    PickedEntity entity = await PhotoPicker.pickAsset(
176
+        if (!single) {
177
+          PickedEntity entity = await PhotoPicker.pickAsset(
172 178
       context: context,
173 179
       padding: 4.0,
174 180
       itemRadio: 1,
175
-      maxSelected: 2,
181
+      maxSelected: 9,
176 182
       provider: I18nProvider.english,
177 183
       rowCount: 4,
178 184
       thumbSize: 150,
179 185
       sortDelegate: SortDelegate.common,
180
-      pickType: PickType.onlyVideo,
186
+      pickType: type,
181 187
       photoPathList: pathList2,
182 188
     );
183 189
 
@@ -197,6 +203,21 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
197 203
       Navigator.push(context,
198 204
           MaterialPageRoute(builder: (_) => PreviewPage(list: preview)));
199 205
     }
206
+        } else {
207
+          final AssetEntity asset = await PhotoPicker.pickSingleAsset(
208
+            context: context,
209
+            padding: 4.0,
210
+            itemRadio: 1,
211
+            provider: I18nProvider.english,
212
+            rowCount: 4,
213
+            thumbSize: 150,
214
+            sortDelegate: SortDelegate.common,
215
+            pickType: type,
216
+            photoPathList: pathList2,
217
+          );
218
+          print(asset);
219
+        }
220
+    
200 221
     setState(() {});
201 222
   }
202 223
 

+ 36
- 0
lib/photo.dart Vedi File

@@ -71,6 +71,7 @@ class PhotoPicker {
71 71
     List<AssetPathEntity> photoPathList,
72 72
     List<AssetEntity> pickedAssetList,
73 73
   }) {
74
+    assert(maxSelected != 0, "maxSelected must be not 0");
74 75
     assert(provider != null, "provider must be not null");
75 76
     assert(context != null, "context must be not null");
76 77
     assert(pickType != null, "pickType must be not null");
@@ -102,6 +103,41 @@ class PhotoPicker {
102 103
     );
103 104
   }
104 105
 
106
+
107
+  static Future<AssetEntity> pickSingleAsset({
108
+    @required BuildContext context,
109
+    int rowCount = 4,
110
+    double padding = 1,
111
+    double itemRadio = 1.0,
112
+    int thumbSize = 180,
113
+    PhotoTheme theme,
114
+    I18nProvider provider = I18nProvider.chinese,
115
+    SortDelegate sortDelegate,
116
+    LoadingDelegate loadingDelegate,
117
+    PickType pickType = PickType.all,
118
+    List<AssetPathEntity> photoPathList,
119
+  }) async {
120
+    final PickedEntity result = await PhotoPicker.pickAsset(
121
+      context: context,
122
+      rowCount: rowCount,
123
+      maxSelected: 1,
124
+      padding: padding,
125
+      itemRadio: itemRadio,
126
+      thumbSize: thumbSize,
127
+      theme: theme,
128
+      provider: provider,
129
+      sortDelegate: sortDelegate,
130
+      loadingDelegate: loadingDelegate,
131
+      pickType: pickType,
132
+      photoPathList: photoPathList,
133
+      pickedAssetList: [],
134
+    );
135
+    if (result.asset.isNotEmpty) {
136
+      return result.asset[0];
137
+    }
138
+    return null;
139
+  }
140
+
105 141
   static Future<File> pickCamera({
106 142
     double maxWidth,
107 143
     double maxHeight,

+ 11
- 2
lib/src/ui/page/photo_main_page.dart Vedi File

@@ -241,7 +241,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
241 241
           ),
242 242
         ),
243 243
         body: _buildBody(),
244
-        bottomNavigationBar: _BottomWidget(
244
+        bottomNavigationBar: options.maxSelected > 1 ? _BottomWidget(
245 245
           key: scaffoldKey,
246 246
           provider: i18nProvider,
247 247
           options: options,
@@ -249,7 +249,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
249 249
           onTapSure: selectedList.isEmpty ? null : sure,
250 250
           selectedProvider: this,
251 251
           galleryListProvider: this,
252
-        ),
252
+        ) : null,
253 253
       ),
254 254
     );
255 255
   }
@@ -403,7 +403,9 @@ class _PhotoMainPageState extends State<PhotoMainPage>
403 403
               loadingDelegate: options.loadingDelegate,
404 404
               badgeDelegate: options.badgeDelegate,
405 405
             ),
406
+            if (options.maxSelected > 1)
406 407
             _buildMask(containsEntity(data)),
408
+            if (options.maxSelected > 1)
407 409
             _buildSelected(data),
408 410
           ],
409 411
         ),
@@ -494,6 +496,13 @@ class _PhotoMainPageState extends State<PhotoMainPage>
494 496
   }
495 497
 
496 498
   void _onItemClick(AssetEntity data, int index) {
499
+    if (options.maxSelected == 1) {
500
+      widget.onClose?.call(PickedEntity(
501
+        asset: [data],
502
+        isFullImage: true,
503
+      ));
504
+      return;
505
+    }
497 506
     var result = PhotoPreviewResult();
498 507
     isPushed = true;
499 508
     Navigator.of(context).push(

+ 26
- 5
pubspec.lock Vedi File

@@ -54,26 +54,40 @@ packages:
54 54
       name: flutter_plugin_android_lifecycle
55 55
       url: "https://pub.flutter-io.cn"
56 56
     source: hosted
57
-    version: "1.0.7"
57
+    version: "1.0.8"
58 58
   flutter_test:
59 59
     dependency: "direct dev"
60 60
     description: flutter
61 61
     source: sdk
62 62
     version: "0.0.0"
63
+  http:
64
+    dependency: transitive
65
+    description:
66
+      name: http
67
+      url: "https://pub.flutter-io.cn"
68
+    source: hosted
69
+    version: "0.12.1"
70
+  http_parser:
71
+    dependency: transitive
72
+    description:
73
+      name: http_parser
74
+      url: "https://pub.flutter-io.cn"
75
+    source: hosted
76
+    version: "3.1.4"
63 77
   image_picker:
64 78
     dependency: "direct main"
65 79
     description:
66 80
       name: image_picker
67 81
       url: "https://pub.flutter-io.cn"
68 82
     source: hosted
69
-    version: "0.6.6+1"
83
+    version: "0.6.7"
70 84
   image_picker_platform_interface:
71 85
     dependency: transitive
72 86
     description:
73 87
       name: image_picker_platform_interface
74 88
       url: "https://pub.flutter-io.cn"
75 89
     source: hosted
76
-    version: "1.0.0"
90
+    version: "1.1.0"
77 91
   matcher:
78 92
     dependency: transitive
79 93
     description:
@@ -102,6 +116,13 @@ packages:
102 116
       url: "https://pub.flutter-io.cn"
103 117
     source: hosted
104 118
     version: "1.7.0"
119
+  pedantic:
120
+    dependency: transitive
121
+    description:
122
+      name: pedantic
123
+      url: "https://pub.flutter-io.cn"
124
+    source: hosted
125
+    version: "1.9.0"
105 126
   photo_manager:
106 127
     dependency: "direct main"
107 128
     description:
@@ -122,7 +143,7 @@ packages:
122 143
       name: provider
123 144
       url: "https://pub.flutter-io.cn"
124 145
     source: hosted
125
-    version: "4.0.5"
146
+    version: "4.1.2"
126 147
   sky_engine:
127 148
     dependency: transitive
128 149
     description: flutter
@@ -186,4 +207,4 @@ packages:
186 207
     version: "2.0.8"
187 208
 sdks:
188 209
   dart: ">=2.7.0 <3.0.0"
189
-  flutter: ">=1.12.13 <2.0.0"
210
+  flutter: ">=1.16.0 <2.0.0"

+ 1
- 1
pubspec.yaml Vedi File

@@ -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.1
3
+version: 0.5.2
4 4
 author: caijinglong<cjl_spy@163.com>
5 5
 homepage: https://github.com/CaiJingLong/flutter_photo
6 6