Browse Source

update pathList

Caijinglong 5 years ago
parent
commit
118958a28d
3 changed files with 52 additions and 9 deletions
  1. 18
    5
      lib/photo.dart
  2. 23
    1
      lib/src/ui/page/photo_main_page.dart
  3. 11
    3
      lib/src/ui/photo_app.dart

+ 18
- 5
lib/photo.dart View File

@@ -3,6 +3,9 @@ library photo;
3 3
 import 'dart:async';
4 4
 
5 5
 import 'package:flutter/material.dart';
6
+
7
+import 'package:photo_manager/photo_manager.dart';
8
+
6 9
 import 'package:photo/src/delegate/badge_delegate.dart';
7 10
 import 'package:photo/src/delegate/checkbox_builder_delegate.dart';
8 11
 import 'package:photo/src/delegate/loading_delegate.dart';
@@ -11,8 +14,6 @@ import 'package:photo/src/entity/options.dart';
11 14
 import 'package:photo/src/provider/i18n_provider.dart';
12 15
 import 'package:photo/src/ui/dialog/not_permission_dialog.dart';
13 16
 import 'package:photo/src/ui/photo_app.dart';
14
-import 'package:photo_manager/photo_manager.dart';
15
-
16 17
 export 'package:photo/src/delegate/checkbox_builder_delegate.dart';
17 18
 export 'package:photo/src/delegate/loading_delegate.dart';
18 19
 export 'package:photo/src/delegate/sort_delegate.dart';
@@ -42,7 +43,9 @@ class PhotoPicker {
42 43
   ///   当用户确定时,返回一个图片[AssetEntity]列表
43 44
   ///
44 45
   ///   当用户取消时返回一个空数组
45
-  ///
46
+  /// 
47
+  ///   [photoList] 一旦设置 则 [pickType]参数无效
48
+  /// 
46 49
   /// 关于参数可以查看readme文档介绍
47 50
   ///
48 51
   /// if user not grand permission, then return null and show a dialog to help user open setting.
@@ -53,6 +56,8 @@ class PhotoPicker {
53 56
   ///   when user sure , return a [AssetEntity] of [List]
54 57
   ///
55 58
   ///   when user cancel selected,result is empty list
59
+  /// 
60
+  ///   when [photoList] is not null , [pickType] invalid
56 61
   ///
57 62
   /// params see readme.md
58 63
   static Future<List<AssetEntity>> pickAsset({
@@ -72,6 +77,7 @@ class PhotoPicker {
72 77
     LoadingDelegate loadingDelegate,
73 78
     PickType pickType = PickType.all,
74 79
     BadgeDelegate badgeDelegate = const DefaultBadgeDelegate(),
80
+    List<AssetPathEntity> photoList,
75 81
   }) {
76 82
     assert(provider != null, "provider must be not null");
77 83
     assert(context != null, "context must be not null");
@@ -108,6 +114,7 @@ class PhotoPicker {
108 114
       context,
109 115
       options,
110 116
       provider,
117
+      photoList,
111 118
     );
112 119
   }
113 120
 
@@ -115,6 +122,7 @@ class PhotoPicker {
115 122
     BuildContext context,
116 123
     Options options,
117 124
     I18nProvider provider,
125
+    List<AssetPathEntity> photoList,
118 126
   ) async {
119 127
     var requestPermission = await PhotoManager.requestPermission();
120 128
     if (requestPermission != true) {
@@ -130,16 +138,21 @@ class PhotoPicker {
130 138
       return null;
131 139
     }
132 140
 
133
-    return _openGalleryContentPage(context, options, provider);
141
+    return _openGalleryContentPage(context, options, provider, photoList);
134 142
   }
135 143
 
136 144
   Future<List<AssetEntity>> _openGalleryContentPage(
137
-      BuildContext context, Options options, I18nProvider provider) async {
145
+    BuildContext context,
146
+    Options options,
147
+    I18nProvider provider,
148
+    List<AssetPathEntity> photoList,
149
+  ) async {
138 150
     return Navigator.of(context).push(
139 151
       MaterialPageRoute(
140 152
         builder: (ctx) => PhotoApp(
141 153
               options: options,
142 154
               provider: provider,
155
+              photoList: photoList,
143 156
             ),
144 157
       ),
145 158
     );

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

@@ -17,11 +17,13 @@ import 'package:photo_manager/photo_manager.dart';
17 17
 class PhotoMainPage extends StatefulWidget {
18 18
   final ValueChanged<List<AssetEntity>> onClose;
19 19
   final Options options;
20
+  final List<AssetPathEntity> photoList;
20 21
 
21 22
   const PhotoMainPage({
22 23
     Key key,
23 24
     this.onClose,
24 25
     this.options,
26
+    this.photoList,
25 27
   }) : super(key: key);
26 28
 
27 29
   @override
@@ -155,7 +157,27 @@ class _PhotoMainPageState extends State<PhotoMainPage>
155 157
     );
156 158
   }
157 159
 
158
-  Future<void> _refreshList() async {
160
+  void _refreshList() {
161
+    if (widget.photoList != null && widget.photoList.isNotEmpty) {
162
+      _refreshListFromWidget();
163
+      return;
164
+    }
165
+
166
+    _refreshListFromGallery();
167
+  }
168
+
169
+  Future<void> _refreshListFromWidget() async {
170
+    galleryPathList.clear();
171
+    galleryPathList.addAll(widget.photoList);
172
+    this.list.clear();
173
+    var assetList = await galleryPathList[0].assetList;
174
+    this.list.addAll(assetList);
175
+    setState(() {
176
+      _isInit = true;
177
+    });
178
+  }
179
+
180
+  Future<void> _refreshListFromGallery() async {
159 181
     List<AssetPathEntity> pathList;
160 182
     switch (options.pickType) {
161 183
       case PickType.onlyImage:

+ 11
- 3
lib/src/ui/photo_app.dart View File

@@ -1,15 +1,22 @@
1 1
 import 'package:flutter/material.dart';
2
+
3
+import 'package:photo_manager/photo_manager.dart';
4
+
2 5
 import 'package:photo/src/entity/options.dart';
3 6
 import 'package:photo/src/provider/config_provider.dart';
4 7
 import 'package:photo/src/provider/i18n_provider.dart';
5 8
 import 'package:photo/src/ui/page/photo_main_page.dart';
6
-import 'package:photo_manager/photo_manager.dart';
7 9
 
8 10
 class PhotoApp extends StatelessWidget {
9 11
   final Options options;
10 12
   final I18nProvider provider;
11
-
12
-  const PhotoApp({Key key, this.options, this.provider}) : super(key: key);
13
+  final List<AssetPathEntity> photoList;
14
+  const PhotoApp({
15
+    Key key,
16
+    this.options,
17
+    this.provider,
18
+    this.photoList,
19
+  }) : super(key: key);
13 20
 
14 21
   @override
15 22
   Widget build(BuildContext context) {
@@ -21,6 +28,7 @@ class PhotoApp extends StatelessWidget {
21 28
           Navigator.pop(context, value);
22 29
         },
23 30
         options: options,
31
+        photoList: photoList,
24 32
       ),
25 33
     );
26 34
   }