Skip to content

Commit 93c4612

Browse files
committed
✨ Add preventGIFPicker method
1 parent 79a3111 commit 93c4612

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

example/lib/constants/picker_method.dart

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ class PickMethod {
182182
icon: '⏳',
183183
name: 'Custom filter options',
184184
description: 'Add filter options for the picker.',
185-
method: (
186-
BuildContext context,
187-
List<AssetEntity> assets,
188-
) {
185+
method: (BuildContext context, List<AssetEntity> assets) {
189186
return AssetPicker.pickAssets(
190187
context,
191188
maxAssets: maxAssetsCount,
@@ -210,11 +207,8 @@ class PickMethod {
210207
icon: '➕',
211208
name: 'Prepend special item',
212209
description: 'A special item will prepend to the assets grid.',
213-
method: (
214-
BuildContext context,
215-
List<AssetEntity> assets,
216-
) async {
217-
return await AssetPicker.pickAssets(
210+
method: (BuildContext context, List<AssetEntity> assets) {
211+
return AssetPicker.pickAssets(
218212
context,
219213
maxAssets: maxAssetsCount,
220214
selectedAssets: assets,
@@ -235,11 +229,8 @@ class PickMethod {
235229
icon: '👁️‍🗨️',
236230
name: 'No preview',
237231
description: 'Pick assets like the WhatsApp/MegaTok pattern.',
238-
method: (
239-
BuildContext context,
240-
List<AssetEntity> assets,
241-
) async {
242-
return await AssetPicker.pickAssets(
232+
method: (BuildContext context, List<AssetEntity> assets) {
233+
return AssetPicker.pickAssets(
243234
context,
244235
maxAssets: maxAssetsCount,
245236
selectedAssets: assets,
@@ -284,11 +275,8 @@ class PickMethod {
284275
name: 'Change Languages',
285276
description: 'Pass text delegates to change between languages. '
286277
'(e.g. EnglishTextDelegate)',
287-
method: (
288-
BuildContext context,
289-
List<AssetEntity> assets,
290-
) async {
291-
return await AssetPicker.pickAssets(
278+
method: (BuildContext context, List<AssetEntity> assets) {
279+
return AssetPicker.pickAssets(
292280
context,
293281
maxAssets: maxAssetsCount,
294282
selectedAssets: assets,
@@ -298,6 +286,28 @@ class PickMethod {
298286
);
299287
}
300288

289+
factory PickMethod.preventGIFPicked(int maxAssetsCount) {
290+
return PickMethod(
291+
icon: '🈲',
292+
name: 'Prevent GIF being picked',
293+
description: 'Use selectPredicate to banned GIF picking when tapped.',
294+
method: (BuildContext context, List<AssetEntity> assets) {
295+
return AssetPicker.pickAssets(
296+
context,
297+
maxAssets: maxAssetsCount,
298+
selectedAssets: assets,
299+
selectPredicate: (BuildContext c, AssetEntity a, bool isSelected) {
300+
print('Asset title: ${a.title}');
301+
if (a.title?.endsWith('.gif') == true) {
302+
return false;
303+
}
304+
return true;
305+
}
306+
);
307+
},
308+
);
309+
}
310+
301311
final String icon;
302312
final String name;
303313
final String description;

example/lib/pages/multi_assets_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
4949
),
5050
PickMethod.noPreview(maxAssetsCount),
5151
PickMethod.customFilterOptions(maxAssetsCount),
52+
PickMethod.preventGIFPicked(maxAssetsCount),
5253
PickMethod.keepScrollOffset(
5354
provider: () => keepScrollProvider,
5455
delegate: () => keepScrollDelegate!,

example/lib/pages/single_assets_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class _SingleAssetPageState extends State<SingleAssetPage>
3737
PickMethod.threeItemsGrid(maxAssetsCount),
3838
PickMethod.prependItem(maxAssetsCount),
3939
PickMethod.customFilterOptions(maxAssetsCount),
40+
PickMethod.preventGIFPicked(maxAssetsCount),
4041
PickMethod.noPreview(maxAssetsCount),
4142
];
4243
}

0 commit comments

Comments
 (0)