4
4
///
5
5
import 'package:flutter/material.dart' ;
6
6
import 'package:wechat_assets_picker/wechat_assets_picker.dart' ;
7
-
8
- import '../main.dart' ;
7
+ import 'package:wechat_camera_picker/wechat_camera_picker.dart' ;
9
8
10
9
class PickMethodModel {
11
10
const PickMethodModel ({
@@ -15,29 +14,202 @@ class PickMethodModel {
15
14
required this .method,
16
15
});
17
16
17
+ factory PickMethodModel .image (int maxAssetsCount) {
18
+ return PickMethodModel (
19
+ icon: '🖼️' ,
20
+ name: 'Image picker' ,
21
+ description: 'Only pick image from device.' ,
22
+ method: (BuildContext context, List <AssetEntity > assets) {
23
+ return AssetPicker .pickAssets (
24
+ context,
25
+ maxAssets: maxAssetsCount,
26
+ selectedAssets: assets,
27
+ requestType: RequestType .image,
28
+ );
29
+ },
30
+ );
31
+ }
32
+
33
+ factory PickMethodModel .video (int maxAssetsCount) {
34
+ return PickMethodModel (
35
+ icon: '🎞' ,
36
+ name: 'Video picker' ,
37
+ description: 'Only pick video from device.' ,
38
+ method: (BuildContext context, List <AssetEntity > assets) {
39
+ return AssetPicker .pickAssets (
40
+ context,
41
+ maxAssets: maxAssetsCount,
42
+ selectedAssets: assets,
43
+ requestType: RequestType .video,
44
+ );
45
+ },
46
+ );
47
+ }
48
+
49
+ factory PickMethodModel .audio (int maxAssetsCount) {
50
+ return PickMethodModel (
51
+ icon: '🎶' ,
52
+ name: 'Audio picker' ,
53
+ description: 'Only pick audio from device.' ,
54
+ method: (BuildContext context, List <AssetEntity > assets) {
55
+ return AssetPicker .pickAssets (
56
+ context,
57
+ maxAssets: maxAssetsCount,
58
+ selectedAssets: assets,
59
+ requestType: RequestType .audio,
60
+ );
61
+ },
62
+ );
63
+ }
64
+
65
+ factory PickMethodModel .camera ({
66
+ required int maxAssetsCount,
67
+ required Function (BuildContext , AssetEntity ) handleResult,
68
+ }) {
69
+ return PickMethodModel (
70
+ icon: '📷' ,
71
+ name: 'Pick from camera' ,
72
+ description: 'Allow pick an asset through camera.' ,
73
+ method: (BuildContext context, List <AssetEntity > assets) {
74
+ return AssetPicker .pickAssets (
75
+ context,
76
+ maxAssets: maxAssetsCount,
77
+ selectedAssets: assets,
78
+ requestType: RequestType .common,
79
+ specialItemPosition: SpecialItemPosition .prepend,
80
+ specialItemBuilder: (BuildContext context) {
81
+ return GestureDetector (
82
+ behavior: HitTestBehavior .opaque,
83
+ onTap: () async {
84
+ final AssetEntity ? result = await CameraPicker .pickFromCamera (
85
+ context,
86
+ enableRecording: true ,
87
+ );
88
+ if (result != null ) {
89
+ handleResult (context, result);
90
+ }
91
+ },
92
+ child: const Center (
93
+ child: Icon (Icons .camera_enhance, size: 42.0 ),
94
+ ),
95
+ );
96
+ },
97
+ );
98
+ },
99
+ );
100
+ }
101
+
102
+ factory PickMethodModel .common (int maxAssetsCount) {
103
+ return PickMethodModel (
104
+ icon: '📹' ,
105
+ name: 'Common picker' ,
106
+ description: 'Pick images and videos.' ,
107
+ method: (BuildContext context, List <AssetEntity > assets) {
108
+ return AssetPicker .pickAssets (
109
+ context,
110
+ maxAssets: maxAssetsCount,
111
+ selectedAssets: assets,
112
+ requestType: RequestType .common,
113
+ );
114
+ },
115
+ );
116
+ }
117
+
118
+ factory PickMethodModel .threeItemsGrid (int maxAssetsCount) {
119
+ return PickMethodModel (
120
+ icon: '🔲' ,
121
+ name: '3 items grid' ,
122
+ description: 'Picker will served as 3 items on cross axis. '
123
+ '(pageSize must be a multiple of gridCount)' ,
124
+ method: (BuildContext context, List <AssetEntity > assets) {
125
+ return AssetPicker .pickAssets (
126
+ context,
127
+ gridCount: 3 ,
128
+ pageSize: 120 ,
129
+ maxAssets: maxAssetsCount,
130
+ selectedAssets: assets,
131
+ requestType: RequestType .all,
132
+ );
133
+ },
134
+ );
135
+ }
136
+
137
+ factory PickMethodModel .customFilterOptions (int maxAssetsCount) {
138
+ return PickMethodModel (
139
+ icon: '⏳' ,
140
+ name: 'Custom filter options' ,
141
+ description: 'Add filter options for the picker.' ,
142
+ method: (
143
+ BuildContext context,
144
+ List <AssetEntity > assets,
145
+ ) {
146
+ return AssetPicker .pickAssets (
147
+ context,
148
+ maxAssets: maxAssetsCount,
149
+ selectedAssets: assets,
150
+ requestType: RequestType .video,
151
+ filterOptions: FilterOptionGroup ()
152
+ ..setOption (
153
+ AssetType .video,
154
+ const FilterOption (
155
+ durationConstraint: DurationConstraint (
156
+ max: Duration (minutes: 1 ),
157
+ ),
158
+ ),
159
+ ),
160
+ );
161
+ },
162
+ );
163
+ }
164
+
165
+ factory PickMethodModel .prependItem (int maxAssetsCount) {
166
+ return PickMethodModel (
167
+ icon: '➕' ,
168
+ name: 'Prepend special item' ,
169
+ description: 'A special item will prepend to the assets grid.' ,
170
+ method: (
171
+ BuildContext context,
172
+ List <AssetEntity > assets,
173
+ ) async {
174
+ return await AssetPicker .pickAssets (
175
+ context,
176
+ maxAssets: maxAssetsCount,
177
+ selectedAssets: assets,
178
+ requestType: RequestType .common,
179
+ specialItemPosition: SpecialItemPosition .prepend,
180
+ specialItemBuilder: (BuildContext context) {
181
+ return const Center (child: Text ('Custom Widget' ));
182
+ },
183
+ );
184
+ },
185
+ );
186
+ }
187
+
188
+ factory PickMethodModel .noPreview (int maxAssetsCount) {
189
+ return PickMethodModel (
190
+ icon: '👁️🗨️' ,
191
+ name: 'No preview' ,
192
+ description: 'Pick assets like the WhatsApp/MegaTok pattern.' ,
193
+ method: (
194
+ BuildContext context,
195
+ List <AssetEntity > assets,
196
+ ) async {
197
+ return await AssetPicker .pickAssets (
198
+ context,
199
+ maxAssets: maxAssetsCount,
200
+ selectedAssets: assets,
201
+ requestType: RequestType .common,
202
+ specialPickerType: SpecialPickerType .noPreview,
203
+ );
204
+ },
205
+ );
206
+ }
207
+
18
208
final String icon;
19
209
final String name;
20
210
final String description;
21
- final Future <List <AssetEntity >?> Function (BuildContext , List <AssetEntity >)
22
- method;
23
-
24
- static PickMethodModel common = PickMethodModel (
25
- icon: '🖼️' ,
26
- name: 'Image picker' ,
27
- description: 'Simply pick image from device.' ,
28
- method: (
29
- BuildContext context,
30
- List <AssetEntity > assets,
31
- ) async {
32
- return await AssetPicker .pickAssets (
33
- context,
34
- maxAssets: 9 ,
35
- pathThumbSize: 84 ,
36
- gridCount: 4 ,
37
- selectedAssets: assets,
38
- themeColor: themeColor,
39
- requestType: RequestType .image,
40
- );
41
- },
42
- );
211
+ final Future <List <AssetEntity >?> Function (
212
+ BuildContext ,
213
+ List <AssetEntity >,
214
+ ) method;
43
215
}
0 commit comments