Browse Source

Merge pull request #4 from CaiJingLong/0.1.0-pre

update 0.1.0 version
CaiJingLong 6 years ago
parent
commit
c2a8690e4d
No account linked to committer's email address

+ 5
- 0
CHANGELOG.md View File

1
 # CHANGELOG
1
 # CHANGELOG
2
 
2
 
3
+## [0.1.0] support video
4
+API incompatibility
5
+
6
+ImageXXX rename AssetXXX
7
+
3
 ## [0.0.8] fix bug
8
 ## [0.0.8] fix bug
4
 DefaultCheckBoxBuilderDelegate params checkColor not valid bug
9
 DefaultCheckBoxBuilderDelegate params checkColor not valid bug
5
 
10
 

+ 9
- 2
README.md View File

13
 
13
 
14
 ![image](https://github.com/CaiJingLong/some_asset/blob/master/image_picker1.gif)
14
 ![image](https://github.com/CaiJingLong/some_asset/blob/master/image_picker1.gif)
15
 
15
 
16
+## API incompatibility
17
+API incompatibility
18
+
19
+because support video, so the ImagePathEntity and ImageEntity rename to AssetPathEntity and AssetEntity.
20
+
21
+so PhotoPicker.pickImage return type will change to List<AssetEntity>
22
+
16
 ## install
23
 ## install
17
 
24
 
18
 ```yaml
25
 ```yaml
19
 dependencies:
26
 dependencies:
20
-  photo: ^0.0.8
27
+  photo: ^0.1.0
21
 ```
28
 ```
22
 
29
 
23
 ## import
30
 ## import
31
 
38
 
32
 ```dart
39
 ```dart
33
   void _pickImage() async {
40
   void _pickImage() async {
34
-    List<ImageEntity> imgList = await PhotoPicker.pickImage(
41
+    List<AssetEntity> imgList = await PhotoPicker.pickImage(
35
       context: context, // BuildContext requied
42
       context: context, // BuildContext requied
36
 
43
 
37
       /// The following are optional parameters.
44
       /// The following are optional parameters.

+ 1
- 1
example/lib/main.dart View File

30
   String currentSelected = "";
30
   String currentSelected = "";
31
 
31
 
32
   void _pickImage() async {
32
   void _pickImage() async {
33
-    List<ImageEntity> imgList = await PhotoPicker.pickImage(
33
+    List<AssetEntity> imgList = await PhotoPicker.pickImage(
34
       context: context, // BuildContext requied
34
       context: context, // BuildContext requied
35
 
35
 
36
       /// The following are optional parameters.
36
       /// The following are optional parameters.

+ 5
- 5
lib/photo.dart View File

35
   ///
35
   ///
36
   /// 当用户给予权限后
36
   /// 当用户给予权限后
37
   ///
37
   ///
38
-  ///   当用户确定时,返回一个图片[ImageEntity]列表
38
+  ///   当用户确定时,返回一个图片[AssetEntity]列表
39
   ///
39
   ///
40
   ///   当用户取消时
40
   ///   当用户取消时
41
   ///
41
   ///
44
   ///
44
   ///
45
   /// when user give permission.
45
   /// when user give permission.
46
   ///
46
   ///
47
-  ///   when user sure , return a [ImageEntity] of [List]
47
+  ///   when user sure , return a [AssetEntity] of [List]
48
   ///
48
   ///
49
   ///   when user cancel selected,result is empty list
49
   ///   when user cancel selected,result is empty list
50
-  static Future<List<ImageEntity>> pickImage({
50
+  static Future<List<AssetEntity>> pickImage({
51
     @required BuildContext context,
51
     @required BuildContext context,
52
     int rowCount = 4,
52
     int rowCount = 4,
53
     int maxSelected = 9,
53
     int maxSelected = 9,
94
     );
94
     );
95
   }
95
   }
96
 
96
 
97
-  Future<List<ImageEntity>> _pickImage(
97
+  Future<List<AssetEntity>> _pickImage(
98
     BuildContext context,
98
     BuildContext context,
99
     Options options,
99
     Options options,
100
     I18nProvider provider,
100
     I18nProvider provider,
116
     return _openGalleryContentPage(context, options, provider);
116
     return _openGalleryContentPage(context, options, provider);
117
   }
117
   }
118
 
118
 
119
-  Future<List<ImageEntity>> _openGalleryContentPage(
119
+  Future<List<AssetEntity>> _openGalleryContentPage(
120
       BuildContext context, Options options, I18nProvider provider) async {
120
       BuildContext context, Options options, I18nProvider provider) async {
121
     return Navigator.of(context).push(
121
     return Navigator.of(context).push(
122
       MaterialPageRoute(
122
       MaterialPageRoute(

+ 8
- 8
lib/src/delegate/sort_delegate.dart View File

3
 abstract class SortDelegate {
3
 abstract class SortDelegate {
4
   const SortDelegate();
4
   const SortDelegate();
5
 
5
 
6
-  void sort(List<ImagePathEntity> list);
6
+  void sort(List<AssetPathEntity> list);
7
 
7
 
8
   static const none = DefaultSortDelegate();
8
   static const none = DefaultSortDelegate();
9
 
9
 
14
   const DefaultSortDelegate();
14
   const DefaultSortDelegate();
15
 
15
 
16
   @override
16
   @override
17
-  void sort(List<ImagePathEntity> list) {}
17
+  void sort(List<AssetPathEntity> list) {}
18
 }
18
 }
19
 
19
 
20
 class CommonSortDelegate extends SortDelegate {
20
 class CommonSortDelegate extends SortDelegate {
21
   const CommonSortDelegate();
21
   const CommonSortDelegate();
22
 
22
 
23
   @override
23
   @override
24
-  void sort(List<ImagePathEntity> list) {
24
+  void sort(List<AssetPathEntity> list) {
25
     list.sort((path1, path2) {
25
     list.sort((path1, path2) {
26
-      if (path1 == ImagePathEntity.all) {
26
+      if (path1 == AssetPathEntity.all) {
27
         return -1;
27
         return -1;
28
       }
28
       }
29
 
29
 
30
-      if (path2 == ImagePathEntity.all) {
30
+      if (path2 == AssetPathEntity.all) {
31
         return 1;
31
         return 1;
32
       }
32
       }
33
 
33
 
51
     });
51
     });
52
   }
52
   }
53
 
53
 
54
-  int otherSort(ImagePathEntity path1, ImagePathEntity path2) {
54
+  int otherSort(AssetPathEntity path1, AssetPathEntity path2) {
55
     return path1.name.compareTo(path2.name);
55
     return path1.name.compareTo(path2.name);
56
   }
56
   }
57
 
57
 
58
-  bool _isCamera(ImagePathEntity entity) {
58
+  bool _isCamera(AssetPathEntity entity) {
59
     return entity.name.toUpperCase() == "camera".toUpperCase();
59
     return entity.name.toUpperCase() == "camera".toUpperCase();
60
   }
60
   }
61
 
61
 
62
-  bool _isScreenShot(ImagePathEntity entity) {
62
+  bool _isScreenShot(AssetPathEntity entity) {
63
     return entity.name.toUpperCase() == "screenshots".toUpperCase() ||
63
     return entity.name.toUpperCase() == "screenshots".toUpperCase() ||
64
         entity.name.toUpperCase() == "screenshot".toUpperCase();
64
         entity.name.toUpperCase() == "screenshot".toUpperCase();
65
   }
65
   }

+ 3
- 3
lib/src/engine/lru_cache.dart View File

6
 class ImageLruCache {
6
 class ImageLruCache {
7
   static LRUMap<_ImageCacheEntity, Uint8List> _map = LRUMap(500);
7
   static LRUMap<_ImageCacheEntity, Uint8List> _map = LRUMap(500);
8
 
8
 
9
-  static Uint8List getData(ImageEntity entity, [int size = 64]) {
9
+  static Uint8List getData(AssetEntity entity, [int size = 64]) {
10
     return _map.get(_ImageCacheEntity(entity, size));
10
     return _map.get(_ImageCacheEntity(entity, size));
11
   }
11
   }
12
 
12
 
13
-  static void setData(ImageEntity entity, int size, Uint8List list) {
13
+  static void setData(AssetEntity entity, int size, Uint8List list) {
14
     _map.put(_ImageCacheEntity(entity, size), list);
14
     _map.put(_ImageCacheEntity(entity, size), list);
15
   }
15
   }
16
 }
16
 }
17
 
17
 
18
 class _ImageCacheEntity {
18
 class _ImageCacheEntity {
19
-  ImageEntity entity;
19
+  AssetEntity entity;
20
   int size;
20
   int size;
21
 
21
 
22
   _ImageCacheEntity(this.entity, this.size);
22
   _ImageCacheEntity(this.entity, this.size);

+ 1
- 1
lib/src/provider/gallery_list_provider.dart View File

1
 import 'package:photo_manager/photo_manager.dart';
1
 import 'package:photo_manager/photo_manager.dart';
2
 
2
 
3
 abstract class GalleryListProvider {
3
 abstract class GalleryListProvider {
4
-  List<ImagePathEntity> galleryPathList = [];
4
+  List<AssetPathEntity> galleryPathList = [];
5
 }
5
 }

+ 6
- 6
lib/src/provider/selected_provider.dart View File

1
 import 'package:photo_manager/photo_manager.dart';
1
 import 'package:photo_manager/photo_manager.dart';
2
 
2
 
3
 abstract class SelectedProvider {
3
 abstract class SelectedProvider {
4
-  List<ImageEntity> selectedList = [];
4
+  List<AssetEntity> selectedList = [];
5
 
5
 
6
   int get selectedCount => selectedList.length;
6
   int get selectedCount => selectedList.length;
7
 
7
 
8
-  bool containsEntity(ImageEntity entity) {
8
+  bool containsEntity(AssetEntity entity) {
9
     return selectedList.contains(entity);
9
     return selectedList.contains(entity);
10
   }
10
   }
11
 
11
 
12
-  int indexOfSelected(ImageEntity entity) {
12
+  int indexOfSelected(AssetEntity entity) {
13
     return selectedList.indexOf(entity);
13
     return selectedList.indexOf(entity);
14
   }
14
   }
15
 
15
 
16
   bool isUpperLimit();
16
   bool isUpperLimit();
17
 
17
 
18
-  bool addSelectEntity(ImageEntity entity) {
18
+  bool addSelectEntity(AssetEntity entity) {
19
     if (containsEntity(entity)) {
19
     if (containsEntity(entity)) {
20
       return false;
20
       return false;
21
     }
21
     }
26
     return true;
26
     return true;
27
   }
27
   }
28
 
28
 
29
-  bool removeSelectEntity(ImageEntity entity) {
29
+  bool removeSelectEntity(AssetEntity entity) {
30
     return selectedList.remove(entity);
30
     return selectedList.remove(entity);
31
   }
31
   }
32
 
32
 
33
-  void compareAndRemoveEntities(List<ImageEntity> previewSelectedList) {
33
+  void compareAndRemoveEntities(List<AssetEntity> previewSelectedList) {
34
     var srcList = List.of(selectedList);
34
     var srcList = List.of(selectedList);
35
     selectedList.clear();
35
     selectedList.clear();
36
     srcList.forEach((entity) {
36
     srcList.forEach((entity) {

+ 1
- 1
lib/src/ui/dialog/change_gallery_dialog.dart View File

2
 import 'package:photo_manager/photo_manager.dart';
2
 import 'package:photo_manager/photo_manager.dart';
3
 
3
 
4
 class ChangeGalleryDialog extends StatefulWidget {
4
 class ChangeGalleryDialog extends StatefulWidget {
5
-  final List<ImagePathEntity> galleryList;
5
+  final List<AssetPathEntity> galleryList;
6
 
6
 
7
   const ChangeGalleryDialog({Key key, this.galleryList}) : super(key: key);
7
   const ChangeGalleryDialog({Key key, this.galleryList}) : super(key: key);
8
 
8
 

+ 17
- 17
lib/src/ui/page/photo_main_page.dart View File

12
 import 'package:photo_manager/photo_manager.dart';
12
 import 'package:photo_manager/photo_manager.dart';
13
 
13
 
14
 class PhotoMainPage extends StatefulWidget {
14
 class PhotoMainPage extends StatefulWidget {
15
-  final ValueChanged<List<ImageEntity>> onClose;
15
+  final ValueChanged<List<AssetEntity>> onClose;
16
 
16
 
17
   const PhotoMainPage({
17
   const PhotoMainPage({
18
     Key key,
18
     Key key,
29
 
29
 
30
   I18nProvider get i18nProvider => ConfigProvider.of(context).provider;
30
   I18nProvider get i18nProvider => ConfigProvider.of(context).provider;
31
 
31
 
32
-  List<ImageEntity> list = [];
32
+  List<AssetEntity> list = [];
33
 
33
 
34
   Color get themeColor => options.themeColor;
34
   Color get themeColor => options.themeColor;
35
 
35
 
36
-  ImagePathEntity _currentPath = ImagePathEntity.all;
36
+  AssetPathEntity _currentPath = AssetPathEntity.all;
37
 
37
 
38
   bool _isInit = false;
38
   bool _isInit = false;
39
 
39
 
40
-  ImagePathEntity get currentPath {
40
+  AssetPathEntity get currentPath {
41
     if (_currentPath == null) {
41
     if (_currentPath == null) {
42
       return null;
42
       return null;
43
     }
43
     }
44
     return _currentPath;
44
     return _currentPath;
45
   }
45
   }
46
 
46
 
47
-  set currentPath(ImagePathEntity value) {
47
+  set currentPath(AssetPathEntity value) {
48
     _currentPath = value;
48
     _currentPath = value;
49
   }
49
   }
50
 
50
 
151
   }
151
   }
152
 
152
 
153
   void _refreshList() async {
153
   void _refreshList() async {
154
-    var pathList = await PhotoManager.getImagePathList();
154
+    var pathList = await PhotoManager.getAssetPathList();
155
 
155
 
156
     options.sortDelegate.sort(pathList);
156
     options.sortDelegate.sort(pathList);
157
 
157
 
158
     galleryPathList.clear();
158
     galleryPathList.clear();
159
     galleryPathList.addAll(pathList);
159
     galleryPathList.addAll(pathList);
160
 
160
 
161
-    var imageList = await currentPath.imageList;
161
+    var imageList = await currentPath.assetList;
162
     this.list.clear();
162
     this.list.clear();
163
     this.list.addAll(imageList);
163
     this.list.addAll(imageList);
164
     setState(() {
164
     setState(() {
214
     );
214
     );
215
   }
215
   }
216
 
216
 
217
-  Widget _buildSelected(ImageEntity entity) {
217
+  Widget _buildSelected(AssetEntity entity) {
218
     var currentSelected = containsEntity(entity);
218
     var currentSelected = containsEntity(entity);
219
     return Positioned(
219
     return Positioned(
220
       right: 0.0,
220
       right: 0.0,
230
     );
230
     );
231
   }
231
   }
232
 
232
 
233
-  Widget _buildText(ImageEntity entity) {
233
+  Widget _buildText(AssetEntity entity) {
234
     var isSelected = containsEntity(entity);
234
     var isSelected = containsEntity(entity);
235
     Widget child;
235
     Widget child;
236
     BoxDecoration decoration;
236
     BoxDecoration decoration;
263
     );
263
     );
264
   }
264
   }
265
 
265
 
266
-  void changeCheck(bool value, ImageEntity entity) {
266
+  void changeCheck(bool value, AssetEntity entity) {
267
     if (value) {
267
     if (value) {
268
       addSelectEntity(entity);
268
       addSelectEntity(entity);
269
     } else {
269
     } else {
272
     setState(() {});
272
     setState(() {});
273
   }
273
   }
274
 
274
 
275
-  void _onGalleryChange(ImagePathEntity value) {
275
+  void _onGalleryChange(AssetPathEntity value) {
276
     _currentPath = value;
276
     _currentPath = value;
277
 
277
 
278
-    _currentPath.imageList.then((v) {
278
+    _currentPath.assetList.then((v) {
279
       list.clear();
279
       list.clear();
280
       list.addAll(v);
280
       list.addAll(v);
281
       scrollController.jumpTo(0.0);
281
       scrollController.jumpTo(0.0);
283
     });
283
     });
284
   }
284
   }
285
 
285
 
286
-  void _onItemClick(ImageEntity data, int index) {
286
+  void _onItemClick(AssetEntity data, int index) {
287
     var result = new PhotoPreviewResult();
287
     var result = new PhotoPreviewResult();
288
     isPushed = true;
288
     isPushed = true;
289
     Navigator.of(context).push(
289
     Navigator.of(context).push(
343
     );
343
     );
344
   }
344
   }
345
 
345
 
346
-  bool handlePreviewResult(List<ImageEntity> v) {
346
+  bool handlePreviewResult(List<AssetEntity> v) {
347
     if (v == null) {
347
     if (v == null) {
348
       return false;
348
       return false;
349
     }
349
     }
350
-    if (v is List<ImageEntity>) {
350
+    if (v is List<AssetEntity>) {
351
       return true;
351
       return true;
352
     }
352
     }
353
     return false;
353
     return false;
383
 }
383
 }
384
 
384
 
385
 class _BottomWidget extends StatefulWidget {
385
 class _BottomWidget extends StatefulWidget {
386
-  final ValueChanged<ImagePathEntity> onGalleryChange;
386
+  final ValueChanged<AssetPathEntity> onGalleryChange;
387
 
387
 
388
   final Options options;
388
   final Options options;
389
 
389
 
481
 }
481
 }
482
 
482
 
483
 class ImageItem extends StatelessWidget {
483
 class ImageItem extends StatelessWidget {
484
-  final ImageEntity entity;
484
+  final AssetEntity entity;
485
 
485
 
486
   final Color themeColor;
486
   final Color themeColor;
487
 
487
 

+ 11
- 11
lib/src/ui/page/photo_preview_page.dart View File

11
 class PhotoPreviewPage extends StatefulWidget {
11
 class PhotoPreviewPage extends StatefulWidget {
12
   final SelectedProvider selectedProvider;
12
   final SelectedProvider selectedProvider;
13
 
13
 
14
-  final List<ImageEntity> list;
14
+  final List<AssetEntity> list;
15
 
15
 
16
   final int initIndex;
16
   final int initIndex;
17
 
17
 
45
 
45
 
46
   SelectedProvider get selectedProvider => widget.selectedProvider;
46
   SelectedProvider get selectedProvider => widget.selectedProvider;
47
 
47
 
48
-  List<ImageEntity> get list => widget.list;
48
+  List<AssetEntity> get list => widget.list;
49
 
49
 
50
   StreamController<int> pageChangeController = StreamController.broadcast();
50
   StreamController<int> pageChangeController = StreamController.broadcast();
51
 
51
 
58
   /// 缩略图用的数据
58
   /// 缩略图用的数据
59
   ///
59
   ///
60
   /// 用于与provider数据联动
60
   /// 用于与provider数据联动
61
-  List<ImageEntity> get previewList {
61
+  List<AssetEntity> get previewList {
62
     return selectedProvider.selectedList;
62
     return selectedProvider.selectedList;
63
   }
63
   }
64
 
64
 
65
   /// 选中的数据
65
   /// 选中的数据
66
-  List<ImageEntity> _selectedList = [];
66
+  List<AssetEntity> _selectedList = [];
67
 
67
 
68
-  List<ImageEntity> get selectedList {
68
+  List<AssetEntity> get selectedList {
69
     if (changeProviderOnCheckChange) {
69
     if (changeProviderOnCheckChange) {
70
       return previewList;
70
       return previewList;
71
     }
71
     }
237
   Widget _buildItem(BuildContext context, int index) {
237
   Widget _buildItem(BuildContext context, int index) {
238
     var data = list[index];
238
     var data = list[index];
239
     return BigPhotoImage(
239
     return BigPhotoImage(
240
-      imageEntity: data,
240
+      assetEntity: data,
241
     );
241
     );
242
   }
242
   }
243
 
243
 
291
     );
291
     );
292
   }
292
   }
293
 
293
 
294
-  void changeSelected(ImageEntity entity, int index) {
294
+  void changeSelected(AssetEntity entity, int index) {
295
     var itemIndex = list.indexOf(entity);
295
     var itemIndex = list.indexOf(entity);
296
     if (itemIndex != -1) pageController.jumpToPage(itemIndex);
296
     if (itemIndex != -1) pageController.jumpToPage(itemIndex);
297
   }
297
   }
302
 }
302
 }
303
 
303
 
304
 class BigPhotoImage extends StatefulWidget {
304
 class BigPhotoImage extends StatefulWidget {
305
-  final ImageEntity imageEntity;
305
+  final AssetEntity assetEntity;
306
   final Widget loadingWidget;
306
   final Widget loadingWidget;
307
 
307
 
308
   const BigPhotoImage({
308
   const BigPhotoImage({
309
     Key key,
309
     Key key,
310
-    this.imageEntity,
310
+    this.assetEntity,
311
     this.loadingWidget,
311
     this.loadingWidget,
312
   }) : super(key: key);
312
   }) : super(key: key);
313
 
313
 
328
     var height = MediaQuery.of(context).size.height;
328
     var height = MediaQuery.of(context).size.height;
329
     return FutureBuilder(
329
     return FutureBuilder(
330
       future:
330
       future:
331
-          widget.imageEntity.thumbDataWithSize(width.floor(), height.floor()),
331
+          widget.assetEntity.thumbDataWithSize(width.floor(), height.floor()),
332
       builder: (BuildContext context, AsyncSnapshot<Uint8List> snapshot) {
332
       builder: (BuildContext context, AsyncSnapshot<Uint8List> snapshot) {
333
         var file = snapshot.data;
333
         var file = snapshot.data;
334
         if (snapshot.connectionState == ConnectionState.done && file != null) {
334
         if (snapshot.connectionState == ConnectionState.done && file != null) {
350
 }
350
 }
351
 
351
 
352
 class PhotoPreviewResult {
352
 class PhotoPreviewResult {
353
-  List<ImageEntity> previewSelectedList = [];
353
+  List<AssetEntity> previewSelectedList = [];
354
 }
354
 }

+ 1
- 1
lib/src/ui/photo_app.dart View File

17
       provider: provider,
17
       provider: provider,
18
       options: options,
18
       options: options,
19
       child: PhotoMainPage(
19
       child: PhotoMainPage(
20
-        onClose: (List<ImageEntity> value) {
20
+        onClose: (List<AssetEntity> value) {
21
           Navigator.pop(context, value);
21
           Navigator.pop(context, value);
22
         },
22
         },
23
       ),
23
       ),

+ 1
- 1
pubspec.lock View File

213
       name: photo_manager
213
       name: photo_manager
214
       url: "https://pub.flutter-io.cn"
214
       url: "https://pub.flutter-io.cn"
215
     source: hosted
215
     source: hosted
216
-    version: "0.0.3"
216
+    version: "0.1.0"
217
   plugin:
217
   plugin:
218
     dependency: transitive
218
     dependency: transitive
219
     description:
219
     description:

+ 2
- 2
pubspec.yaml View File

1
 name: photo
1
 name: photo
2
 description: image picker, multi picker,use flutter as ui, if you want to build custom ui,you just use photo_manager.
2
 description: image picker, multi picker,use flutter as ui, if you want to build custom ui,you just use photo_manager.
3
-version: 0.0.8
3
+version: 0.1.0
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
 
11
   flutter:
11
   flutter:
12
     sdk: flutter
12
     sdk: flutter
13
 
13
 
14
-  photo_manager: ^0.0.3
14
+  photo_manager: ^0.1.0
15
 #  photo_manager:
15
 #  photo_manager:
16
 #    git:
16
 #    git:
17
 #      url: https://github.com/CaiJingLong/flutter_photo_manager.git
17
 #      url: https://github.com/CaiJingLong/flutter_photo_manager.git