|
@@ -1,11 +1,11 @@
|
1
|
1
|
library photo;
|
2
|
2
|
|
3
|
3
|
import 'dart:async';
|
4
|
|
-import 'dart:io';
|
5
|
4
|
|
6
|
5
|
import 'package:flutter/material.dart';
|
7
|
6
|
import 'package:image_picker/image_picker.dart';
|
8
|
7
|
import 'package:photo/src/entity/_theme.dart';
|
|
8
|
+import 'package:photo/src/permission_utils.dart';
|
9
|
9
|
import 'package:photo/src/ui/page/photo_list_page.dart';
|
10
|
10
|
import 'package:photo/src/ui/page/photo_main_page.dart';
|
11
|
11
|
|
|
@@ -17,7 +17,6 @@ import 'package:photo/src/delegate/loading_delegate.dart';
|
17
|
17
|
import 'package:photo/src/delegate/sort_delegate.dart';
|
18
|
18
|
import 'package:photo/src/entity/options.dart';
|
19
|
19
|
import 'package:photo/src/provider/i18n_provider.dart';
|
20
|
|
-import 'package:photo/src/ui/dialog/not_permission_dialog.dart';
|
21
|
20
|
import 'package:provider/provider.dart';
|
22
|
21
|
|
23
|
22
|
import 'src/provider/config_provider.dart';
|
|
@@ -29,8 +28,8 @@ export 'package:photo/src/provider/i18n_provider.dart'
|
29
|
28
|
export 'package:photo/src/entity/options.dart' show PickType, PickedEntity;
|
30
|
29
|
export 'package:photo/src/delegate/badge_delegate.dart';
|
31
|
30
|
export 'package:photo/src/entity/_theme.dart';
|
32
|
|
-export 'package:image_picker/image_picker.dart' show CameraDevice;
|
33
|
|
-export 'package:photo_manager/photo_manager.dart' show AssetEntity;
|
|
31
|
+export 'package:image_picker/image_picker.dart' show CameraDevice, PickedFile;
|
|
32
|
+export 'package:photo_manager/photo_manager.dart' show AssetEntity, AssetType;
|
34
|
33
|
|
35
|
34
|
class PhotoPicker {
|
36
|
35
|
static PhotoPicker _instance;
|
|
@@ -61,7 +60,7 @@ class PhotoPicker {
|
61
|
60
|
@required BuildContext context,
|
62
|
61
|
int rowCount = 4,
|
63
|
62
|
int maxSelected = 9,
|
64
|
|
- double padding = 1,
|
|
63
|
+ double padding = 0.5,
|
65
|
64
|
double itemRadio = 1.0,
|
66
|
65
|
int thumbSize = 180,
|
67
|
66
|
PhotoTheme theme,
|
|
@@ -91,7 +90,7 @@ class PhotoPicker {
|
91
|
90
|
sortDelegate: sortDelegate,
|
92
|
91
|
checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(),
|
93
|
92
|
loadingDelegate: loadingDelegate,
|
94
|
|
- badgeDelegate: DefaultBadgeDelegate(),
|
|
93
|
+ badgeDelegate: DurationBadgeDelegate(),
|
95
|
94
|
pickType: pickType,
|
96
|
95
|
);
|
97
|
96
|
|
|
@@ -104,11 +103,10 @@ class PhotoPicker {
|
104
|
103
|
);
|
105
|
104
|
}
|
106
|
105
|
|
107
|
|
-
|
108
|
106
|
static Future<AssetEntity> pickSingleAsset({
|
109
|
107
|
@required BuildContext context,
|
110
|
108
|
int rowCount = 4,
|
111
|
|
- double padding = 1,
|
|
109
|
+ double padding = 0.5,
|
112
|
110
|
double itemRadio = 1.0,
|
113
|
111
|
int thumbSize = 180,
|
114
|
112
|
PhotoTheme theme,
|
|
@@ -139,19 +137,24 @@ class PhotoPicker {
|
139
|
137
|
return null;
|
140
|
138
|
}
|
141
|
139
|
|
142
|
|
- static Future<File> pickCamera({
|
|
140
|
+ static Future<PickedFile> pickCamera({
|
143
|
141
|
double maxWidth,
|
144
|
142
|
double maxHeight,
|
145
|
143
|
int imageQuality,
|
146
|
144
|
CameraDevice preferredCameraDevice = CameraDevice.rear,
|
147
|
145
|
}) async {
|
148
|
|
- return ImagePicker.pickImage(
|
149
|
|
- source: ImageSource.camera,
|
150
|
|
- maxWidth: maxWidth,
|
151
|
|
- maxHeight: maxHeight,
|
152
|
|
- imageQuality: imageQuality,
|
153
|
|
- preferredCameraDevice: preferredCameraDevice,
|
154
|
|
- );
|
|
146
|
+ final bool status = await PermissionUtils.canPermission(Permission.camera);
|
|
147
|
+ if (!status) {
|
|
148
|
+ throw 'permission denied';
|
|
149
|
+ } else {
|
|
150
|
+ return ImagePicker().getImage(
|
|
151
|
+ source: ImageSource.camera,
|
|
152
|
+ maxWidth: maxWidth,
|
|
153
|
+ maxHeight: maxHeight,
|
|
154
|
+ imageQuality: imageQuality,
|
|
155
|
+ preferredCameraDevice: preferredCameraDevice,
|
|
156
|
+ );
|
|
157
|
+ }
|
155
|
158
|
}
|
156
|
159
|
|
157
|
160
|
Future<PickedEntity> _pickAsset(
|
|
@@ -161,15 +164,18 @@ class PhotoPicker {
|
161
|
164
|
List<AssetPathEntity> photoList,
|
162
|
165
|
List<AssetEntity> pickedAssetList,
|
163
|
166
|
) async {
|
164
|
|
- await requestPermission(context, provider: provider);
|
165
|
|
-
|
166
|
|
- return _openGalleryContentPage(
|
167
|
|
- context,
|
168
|
|
- options,
|
169
|
|
- provider,
|
170
|
|
- photoList,
|
171
|
|
- pickedAssetList,
|
172
|
|
- );
|
|
167
|
+ final bool status = await PermissionUtils.canMultiplePermission([Permission.photos, Permission.storage]);
|
|
168
|
+ if (!status) {
|
|
169
|
+ throw 'permission denied';
|
|
170
|
+ } else {
|
|
171
|
+ return _openGalleryContentPage(
|
|
172
|
+ context,
|
|
173
|
+ options,
|
|
174
|
+ provider,
|
|
175
|
+ photoList,
|
|
176
|
+ pickedAssetList,
|
|
177
|
+ );
|
|
178
|
+ }
|
173
|
179
|
}
|
174
|
180
|
|
175
|
181
|
static Widget buildGallery({
|
|
@@ -201,7 +207,7 @@ class PhotoPicker {
|
201
|
207
|
sortDelegate: sortDelegate,
|
202
|
208
|
checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(),
|
203
|
209
|
loadingDelegate: loadingDelegate,
|
204
|
|
- badgeDelegate: DefaultBadgeDelegate(),
|
|
210
|
+ badgeDelegate: DurationBadgeDelegate(),
|
205
|
211
|
pickType: pickType,
|
206
|
212
|
);
|
207
|
213
|
assert(provider != null, "provider must be not null");
|
|
@@ -222,21 +228,22 @@ class PhotoPicker {
|
222
|
228
|
);
|
223
|
229
|
}
|
224
|
230
|
|
225
|
|
- Future<void> requestPermission(BuildContext context,
|
226
|
|
- {@required I18nProvider provider}) async {
|
227
|
|
- var requestPermission = await PhotoManager.requestPermission();
|
228
|
|
- if (requestPermission != true) {
|
229
|
|
- var result = await showDialog(
|
230
|
|
- context: context,
|
231
|
|
- builder: (ctx) => NotPermissionDialog(
|
232
|
|
- provider.getNotPermissionText(),
|
233
|
|
- ),
|
234
|
|
- );
|
235
|
|
- if (result == true) {
|
236
|
|
- PhotoManager.openSetting();
|
237
|
|
- }
|
238
|
|
- return null;
|
239
|
|
- }
|
|
231
|
+ Future<bool> requestPermission({@required I18nProvider provider, @required List<Permission> permissions}) async {
|
|
232
|
+ final bool status =
|
|
233
|
+ await PermissionUtils.canMultiplePermission(permissions);
|
|
234
|
+ // if (!status) {
|
|
235
|
+ // var result = await showDialog(
|
|
236
|
+ // context: context,
|
|
237
|
+ // builder: (ctx) => NotPermissionDialog(
|
|
238
|
+ // provider.getNotPermissionText(),
|
|
239
|
+ // ),
|
|
240
|
+ // );
|
|
241
|
+ // if (result == true) {
|
|
242
|
+ // PhotoManager.openSetting();
|
|
243
|
+ // }
|
|
244
|
+ // return false;
|
|
245
|
+ // }
|
|
246
|
+ return status;
|
240
|
247
|
}
|
241
|
248
|
|
242
|
249
|
Future<PickedEntity> _openGalleryContentPage(
|