Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag Select Special Option for Asset Picker #658

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions example/lib/constants/picker_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,24 @@ class PickMethod {
);
}

factory PickMethod.dragSelect(BuildContext context, int maxAssetsCount) {
return PickMethod(
icon: '📲',
name: context.l10n.pickMethodDragSelectName,
description: context.l10n.pickMethodDragSelectDescription,
method: (BuildContext context, List<AssetEntity> assets) {
return AssetPicker.pickAssets(
context,
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
selectedAssets: assets,
specialPickerType: SpecialPickerType.dragSelect,
),
);
},
);
}

factory PickMethod.keepScrollOffset({
required BuildContext context,
required DefaultAssetPickerBuilderDelegate Function() delegate,
Expand Down
2 changes: 2 additions & 0 deletions example/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"pickMethodPrependItemDescription": "A special item will prepend to the assets grid.",
"pickMethodNoPreviewName": "No preview",
"pickMethodNoPreviewDescription": "You cannot preview assets during the picking, the behavior is like the WhatsApp/MegaTok pattern.",
"pickMethodDragSelectName": "Drag Select",
"pickMethodDragSelectDescription": "You can drag and select assets in this mode.",
"pickMethodKeepScrollOffsetName": "Keep scroll offset",
"pickMethodKeepScrollOffsetDescription": "Pick assets from same scroll position.",
"pickMethodChangeLanguagesName": "Change Languages",
Expand Down
2 changes: 2 additions & 0 deletions example/lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"pickMethodPrependItemDescription": "网格的靠前位置会添加一个自定义的 widget。",
"pickMethodNoPreviewName": "禁止预览",
"pickMethodNoPreviewDescription": "无法预览选择的资源,与 WhatsApp/MegaTok 的行为类似。",
"pickMethodDragSelectName": "拖动选择",
"pickMethodDragSelectDescription": "您可以在此模式下拖动并选择资源。",
"pickMethodKeepScrollOffsetName": "保持滚动位置",
"pickMethodKeepScrollOffsetDescription": "可以从上次滚动到的位置再次开始选择。",
"pickMethodChangeLanguagesName": "更改语言",
Expand Down
14 changes: 14 additions & 0 deletions example/lib/l10n/gen/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:intl/intl.dart' as intl;
import 'app_localizations_en.dart';
import 'app_localizations_zh.dart';

// ignore_for_file: type=lint

/// Callers can lookup localized strings with an instance of AppLocalizations
/// returned by `AppLocalizations.of(context)`.
///
Expand Down Expand Up @@ -276,6 +278,18 @@ abstract class AppLocalizations {
/// **'You cannot preview assets during the picking, the behavior is like the WhatsApp/MegaTok pattern.'**
String get pickMethodNoPreviewDescription;

/// No description provided for @pickMethodDragSelectName.
///
/// In en, this message translates to:
/// **'Drag Select'**
String get pickMethodDragSelectName;

/// No description provided for @pickMethodDragSelectDescription.
///
/// In en, this message translates to:
/// **'You can drag and select assets in this mode.'**
String get pickMethodDragSelectDescription;

/// No description provided for @pickMethodKeepScrollOffsetName.
///
/// In en, this message translates to:
Expand Down
9 changes: 9 additions & 0 deletions example/lib/l10n/gen/app_localizations_en.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'app_localizations.dart';

// ignore_for_file: type=lint

/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale);
Expand Down Expand Up @@ -106,6 +108,13 @@ class AppLocalizationsEn extends AppLocalizations {
String get pickMethodNoPreviewDescription =>
'You cannot preview assets during the picking, the behavior is like the WhatsApp/MegaTok pattern.';

@override
String get pickMethodDragSelectName => 'Drag Select';

@override
String get pickMethodDragSelectDescription =>
'You can drag and select assets in this mode.';

@override
String get pickMethodKeepScrollOffsetName => 'Keep scroll offset';

Expand Down
8 changes: 8 additions & 0 deletions example/lib/l10n/gen/app_localizations_zh.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'app_localizations.dart';

// ignore_for_file: type=lint

/// The translations for Chinese (`zh`).
class AppLocalizationsZh extends AppLocalizations {
AppLocalizationsZh([String locale = 'zh']) : super(locale);
Expand Down Expand Up @@ -100,6 +102,12 @@ class AppLocalizationsZh extends AppLocalizations {
String get pickMethodNoPreviewDescription =>
'无法预览选择的资源,与 WhatsApp/MegaTok 的行为类似。';

@override
String get pickMethodDragSelectName => '拖动选择';

@override
String get pickMethodDragSelectDescription => '您可以在此模式下拖动并选择资源。';

@override
String get pickMethodKeepScrollOffsetName => '保持滚动位置';

Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/multi_assets_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
},
),
PickMethod.noPreview(context, maxAssetsCount),
PickMethod.dragSelect(context, maxAssetsCount),
PickMethod.customizableTheme(context, maxAssetsCount),
PickMethod.pathNameBuilder(context, maxAssetsCount),
PickMethod.customFilterOptions(context, maxAssetsCount),
Expand Down
4 changes: 4 additions & 0 deletions lib/src/constants/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@ class AssetPickerConfig {
/// no more images can be selected.
/// * [SpecialPickerType.noPreview] Disable preview of asset;
/// Clicking on an asset selects it.
/// * [SpecialPickerType.dragSelect] User able to drag
/// and select assets.
///
/// 这里包含一些特殊选择类型:
/// * [SpecialPickerType.wechatMoment] 微信朋友圈模式。
/// 当用户选择了视频,将不能选择图片。
/// * [SpecialPickerType.noPreview] 禁用资源预览。
/// 多选时单击资产将直接选中,单选时选中并返回。
/// * [SpecialPickerType.dragSelect] 用户可以拖动
/// 并选择资产。
final SpecialPickerType? specialPickerType;

/// Whether the picker should save the scroll offset between pushes and pops.
Expand Down
9 changes: 9 additions & 0 deletions lib/src/constants/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ enum SpecialPickerType {
/// 在多选模式下无论点击选择指示还是 item 都将触发选择,
/// 而在单选模式下将直接返回点击的资源。
noPreview,

/// Drag and Select.
/// 禁用资源预览
///
/// The user can drag and select items. Must be in multiple select mode.
/// Triggers all the settings of preview mode plus drag and select.
/// 用户可以拖动并选择项目。必须处于多选模式
/// 触发预览模式的所有设置以及拖动和选择。
dragSelect,
}

/// Provide an item slot for custom widget insertion.
Expand Down
Loading
Loading