Browse Source

Update picked asset for list.

Caijinglong 4 years ago
parent
commit
3509ac0532

+ 23
- 0
example/lib/icon_text_button.dart View File

1
+import 'package:flutter/material.dart';
2
+
3
+class IconTextButton extends StatelessWidget {
4
+  final IconData icon;
5
+  final String text;
6
+  final Function onTap;
7
+
8
+  const IconTextButton({Key key, this.icon, this.text, this.onTap})
9
+      : super(key: key);
10
+
11
+  @override
12
+  Widget build(BuildContext context) {
13
+    return InkWell(
14
+      onTap: onTap,
15
+      child: Container(
16
+        child: ListTile(
17
+          leading: Icon(icon ?? Icons.device_unknown),
18
+          title: Text(text ?? ""),
19
+        ),
20
+      ),
21
+    );
22
+  }
23
+}

+ 26
- 31
example/lib/main.dart View File

5
 import 'package:photo_manager/photo_manager.dart';
5
 import 'package:photo_manager/photo_manager.dart';
6
 
6
 
7
 import './preview.dart';
7
 import './preview.dart';
8
+import 'icon_text_button.dart';
9
+import 'picked_example.dart';
8
 
10
 
9
 void main() => runApp(MyApp());
11
 void main() => runApp(MyApp());
10
 
12
 
16
       child: MaterialApp(
18
       child: MaterialApp(
17
         title: 'Pick Image Demo',
19
         title: 'Pick Image Demo',
18
         theme: ThemeData(
20
         theme: ThemeData(
19
-          primarySwatch: Colors.blue,
21
+          primarySwatch: Colors.lime,
20
         ),
22
         ),
21
         home: MyHomePage(title: 'Pick Image Demo'),
23
         home: MyHomePage(title: 'Pick Image Demo'),
22
       ),
24
       ),
80
           child: Column(
82
           child: Column(
81
             children: <Widget>[
83
             children: <Widget>[
82
               IconTextButton(
84
               IconTextButton(
83
-                  icon: Icons.photo,
84
-                  text: "photo",
85
-                  onTap: () => _pickAsset(PickType.onlyImage)),
85
+                icon: Icons.photo,
86
+                text: "photo",
87
+                onTap: () => _pickAsset(PickType.onlyImage),
88
+              ),
89
+              IconTextButton(
90
+                icon: Icons.videocam,
91
+                text: "video",
92
+                onTap: () => _pickAsset(PickType.onlyVideo),
93
+              ),
86
               IconTextButton(
94
               IconTextButton(
87
-                  icon: Icons.videocam,
88
-                  text: "video",
89
-                  onTap: () => _pickAsset(PickType.onlyVideo)),
95
+                icon: Icons.album,
96
+                text: "all",
97
+                onTap: () => _pickAsset(PickType.all),
98
+              ),
90
               IconTextButton(
99
               IconTextButton(
91
-                  icon: Icons.album,
92
-                  text: "all",
93
-                  onTap: () => _pickAsset(PickType.all)),
94
-              Text(
95
-                '$currentSelected',
96
-                textAlign: TextAlign.center,
100
+                icon: CupertinoIcons.reply_all,
101
+                text: "Picked asset example.",
102
+                onTap: () => routePage(PickedExample()),
97
               ),
103
               ),
98
             ],
104
             ],
99
           ),
105
           ),
182
     }
188
     }
183
     setState(() {});
189
     setState(() {});
184
   }
190
   }
185
-}
186
-
187
-class IconTextButton extends StatelessWidget {
188
-  final IconData icon;
189
-  final String text;
190
-  final Function onTap;
191
 
191
 
192
-  const IconTextButton({Key key, this.icon, this.text, this.onTap})
193
-      : super(key: key);
194
-
195
-  @override
196
-  Widget build(BuildContext context) {
197
-    return InkWell(
198
-      onTap: onTap,
199
-      child: Container(
200
-        child: ListTile(
201
-          leading: Icon(icon ?? Icons.device_unknown),
202
-          title: Text(text ?? ""),
203
-        ),
192
+  void routePage(Widget widget) {
193
+    Navigator.push(
194
+      context,
195
+      MaterialPageRoute(
196
+        builder: (BuildContext context) {
197
+          return widget;
198
+        },
204
       ),
199
       ),
205
     );
200
     );
206
   }
201
   }

+ 48
- 0
example/lib/picked_example.dart View File

1
+import 'package:flutter/cupertino.dart';
2
+import 'package:flutter/material.dart';
3
+import 'package:photo/photo.dart';
4
+
5
+import 'icon_text_button.dart';
6
+import 'package:photo_manager/photo_manager.dart';
7
+
8
+class PickedExample extends StatefulWidget {
9
+  @override
10
+  _PickedExampleState createState() => _PickedExampleState();
11
+}
12
+
13
+class _PickedExampleState extends State<PickedExample> {
14
+  List<AssetEntity> picked = [];
15
+
16
+  @override
17
+  Widget build(BuildContext context) {
18
+    return Scaffold(
19
+      appBar: AppBar(
20
+        title: Text("Cross Picked asset"),
21
+      ),
22
+      body: Column(
23
+        children: <Widget>[
24
+          IconTextButton(
25
+            icon: Icons.assignment,
26
+            text: "Pick asset",
27
+            onTap: _pickAsset,
28
+          ),
29
+          ListTile(
30
+            title: Text("picked asset count = ${picked.length}"),
31
+          ),
32
+        ],
33
+      ),
34
+    );
35
+  }
36
+
37
+  void _pickAsset() async {
38
+    final result = await PhotoPicker.pickAsset(
39
+      context: context,
40
+      pickedAssetList: picked,
41
+    );
42
+    if (result != null && result.isNotEmpty) {
43
+      picked.clear();
44
+      picked.addAll(result);
45
+      setState(() {});
46
+    }
47
+  }
48
+}

+ 0
- 2
lib/src/provider/asset_provider.dart View File

31
   bool get noMore => getPaging()?.noMore ?? false;
31
   bool get noMore => getPaging()?.noMore ?? false;
32
 
32
 
33
   int get count => data?.length ?? 0;
33
   int get count => data?.length ?? 0;
34
-
35
-  void addPickedAssetList() {}
36
 }
34
 }
37
 
35
 
38
 class AssetPaging {
36
 class AssetPaging {

+ 2
- 4
lib/src/provider/config_provider.dart View File

8
   final Options options;
8
   final Options options;
9
   final I18nProvider provider;
9
   final I18nProvider provider;
10
   final AssetProvider assetProvider = AssetProvider();
10
   final AssetProvider assetProvider = AssetProvider();
11
+  final List<AssetEntity> pickedAssetList;
11
   PhotoPickerProvider({
12
   PhotoPickerProvider({
12
     @required this.options,
13
     @required this.options,
13
     @required this.provider,
14
     @required this.provider,
14
     @required Widget child,
15
     @required Widget child,
16
+    this.pickedAssetList,
15
     Key key,
17
     Key key,
16
   }) : super(key: key, child: child);
18
   }) : super(key: key, child: child);
17
 
19
 
25
 
27
 
26
   static AssetProvider assetProviderOf(BuildContext context) =>
28
   static AssetProvider assetProviderOf(BuildContext context) =>
27
       of(context).assetProvider;
29
       of(context).assetProvider;
28
-
29
-  void addPickedAssetList(List<AssetEntity> pickedAssetList) {
30
-    assetProvider.addPickedAssetList();
31
-  }
32
 }
30
 }

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

57
       return notExistsList.contains(e);
57
       return notExistsList.contains(e);
58
     });
58
     });
59
   }
59
   }
60
+
61
+  addPickedAsset(List<AssetEntity> list) {
62
+    for (final entity in list) {
63
+      addSelectEntity(entity);
64
+    }
65
+  }
60
 }
66
 }

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

92
   void didChangeDependencies() {
92
   void didChangeDependencies() {
93
     super.didChangeDependencies();
93
     super.didChangeDependencies();
94
     if (!_isInit) {
94
     if (!_isInit) {
95
+      addPickedAsset(PhotoPickerProvider.of(context).pickedAssetList.toList());
95
       _refreshList();
96
       _refreshList();
96
     }
97
     }
97
   }
98
   }

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

25
     final pickerProvider = PhotoPickerProvider(
25
     final pickerProvider = PhotoPickerProvider(
26
       provider: provider,
26
       provider: provider,
27
       options: options,
27
       options: options,
28
+      pickedAssetList: pickedAssetList,
28
       child: PhotoMainPage(
29
       child: PhotoMainPage(
29
         onClose: (List<AssetEntity> value) {
30
         onClose: (List<AssetEntity> value) {
30
           Navigator.pop(context, value);
31
           Navigator.pop(context, value);