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

✨ Support Multiple Special Items #635

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ final List<AssetEntity>? result = await AssetPicker.pickAssets(
| themeColor | `Color?` | 选择器的主题色 | `Color(0xff00bc56)` |
| pickerTheme | `ThemeData?` | 选择器的主题提供,包括查看器 | `null` |
| textDelegate | `AssetPickerTextDelegate?` | 选择器的文本代理构建,用于自定义文本 | `AssetPickerTextDelegate()` |
| specialItemPosition | `SpecialItemPosition` | 允许用户在选择器中添加一个自定义item,并指定位置。 | `SpecialPosition.none` |
| specialItemBuilder | `SpecialItemBuilder?` | 自定义item的构造方法 | `null` |
| specialItems | `List<SpecialItem>` | 自定义item列表 | `const []` |
| loadingIndicatorBuilder | `IndicatorBuilder?` | 加载器的实现 | `null` |
| selectPredicate | `AssetSelectPredicate` | 判断资源可否被选择 | `null` |
| shouldRevertGrid | `bool?` | 判断资源网格是否需要倒序排列 | `null` |
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ Fields in `AssetPickerConfig`:
| themeColor | `Color?` | Main theme color for the picker. | `Color(0xff00bc56)` |
| pickerTheme | `ThemeData?` | Theme data provider for the picker and the viewer. | `null` |
| textDelegate | `AssetPickerTextDelegate?` | Text delegate for the picker, for customize the texts. | `AssetPickerTextDelegate()` |
| specialItemPosition | `SpecialItemPosition` | Allow users set a special item in the picker with several positions. | `SpecialItemPosition.none` |
| specialItemBuilder | `SpecialItemBuilder?` | The widget builder for the special item. | `null` |
| specialItems | `List<SpecialItem>` | List of special items. | `const []` |
| loadingIndicatorBuilder | `IndicatorBuilder?` | Indicates the loading status for the builder. | `null` |
| selectPredicate | `AssetSelectPredicate` | Predicate whether an asset can be selected or unselected. | `null` |
| shouldRevertGrid | `bool?` | Whether the assets grid should revert. | `null` |
Expand Down
256 changes: 172 additions & 84 deletions example/lib/constants/picker_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,39 +135,45 @@ class PickMethod {
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
selectedAssets: assets,
specialItemPosition: SpecialItemPosition.prepend,
specialItemBuilder: (
BuildContext context,
AssetPathEntity? path,
int length,
) {
if (path?.isAll != true) {
return null;
}
return Semantics(
label: textDelegate.sActionUseCameraHint,
button: true,
onTapHint: textDelegate.sActionUseCameraHint,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
Feedback.forTap(context);
final AssetEntity? result = await _pickFromCamera(context);
if (result != null) {
handleResult(context, result);
}
},
child: Container(
padding: const EdgeInsets.all(28.0),
color: Theme.of(context).dividerColor,
child: const FittedBox(
fit: BoxFit.fill,
child: Icon(Icons.camera_enhance),
specialItems: [
SpecialItem(
position: SpecialItemPosition.prepend,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
if (path?.isAll != true) {
return null;
}
return Semantics(
label: textDelegate.sActionUseCameraHint,
button: true,
onTapHint: textDelegate.sActionUseCameraHint,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
Feedback.forTap(context);
final AssetEntity? result =
await _pickFromCamera(context);
if (result != null) {
handleResult(context, result);
}
},
child: Container(
padding: const EdgeInsets.all(28.0),
color: Theme.of(context).dividerColor,
child: const FittedBox(
fit: BoxFit.fill,
child: Icon(Icons.camera_enhance),
),
),
),
),
),
);
},
);
},
),
],
),
);
},
Expand All @@ -186,50 +192,56 @@ class PickMethod {
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
selectedAssets: assets,
specialItemPosition: SpecialItemPosition.prepend,
specialItemBuilder: (
BuildContext context,
AssetPathEntity? path,
int length,
) {
if (path?.isAll != true) {
return null;
}
return Semantics(
label: textDelegate.sActionUseCameraHint,
button: true,
onTapHint: textDelegate.sActionUseCameraHint,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
final AssetEntity? result = await _pickFromCamera(context);
if (result == null) {
return;
}
final picker = context.findAncestorWidgetOfExactType<
AssetPicker<AssetEntity, AssetPathEntity>>()!;
final builder =
picker.builder as DefaultAssetPickerBuilderDelegate;
final p = builder.provider;
await p.switchPath(
PathWrapper<AssetPathEntity>(
path:
await p.currentPath!.path.obtainForNewProperties(),
specialItems: [
SpecialItem(
position: SpecialItemPosition.prepend,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
if (path?.isAll != true) {
return null;
}
return Semantics(
label: textDelegate.sActionUseCameraHint,
button: true,
onTapHint: textDelegate.sActionUseCameraHint,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
final AssetEntity? result =
await _pickFromCamera(context);
if (result == null) {
return;
}
final picker = context.findAncestorWidgetOfExactType<
AssetPicker<AssetEntity, AssetPathEntity>>()!;
final builder =
picker.builder as DefaultAssetPickerBuilderDelegate;
final p = builder.provider;
await p.switchPath(
PathWrapper<AssetPathEntity>(
path: await p.currentPath!.path
.obtainForNewProperties(),
),
);
p.selectAsset(result);
},
child: Container(
padding: const EdgeInsets.all(28.0),
color: Theme.of(context).dividerColor,
child: const FittedBox(
fit: BoxFit.fill,
child: Icon(Icons.camera_enhance),
),
),
);
p.selectAsset(result);
},
child: Container(
padding: const EdgeInsets.all(28.0),
color: Theme.of(context).dividerColor,
child: const FittedBox(
fit: BoxFit.fill,
child: Icon(Icons.camera_enhance),
),
),
),
);
},
);
},
),
],
),
);
},
Expand Down Expand Up @@ -295,16 +307,92 @@ class PickMethod {
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
selectedAssets: assets,
specialItemPosition: SpecialItemPosition.prepend,
specialItemBuilder: (
BuildContext context,
AssetPathEntity? path,
int length,
) {
return const Center(
child: Text('Custom Widget', textAlign: TextAlign.center),
);
},
specialItems: [
SpecialItem(
position: SpecialItemPosition.prepend,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
return const Center(
child: Text('Custom Widget', textAlign: TextAlign.center),
);
},
),
],
),
);
},
);
}

factory PickMethod.multiSpecialItems(
BuildContext context,
int maxAssetsCount,
) {
return PickMethod(
icon: '💡',
name: context.l10n.pickMethodMultiSpecialItemsName,
description: context.l10n.pickMethodMultiSpecialItemsDescription,
method: (BuildContext context, List<AssetEntity> assets) {
return AssetPicker.pickAssets(
context,
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
selectedAssets: assets,
specialItems: [
SpecialItem(
position: SpecialItemPosition.prepend,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
return const Center(
child: Text('Prepand Widget', textAlign: TextAlign.center),
);
},
),
SpecialItem(
position: SpecialItemPosition.append,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
return const Center(
child: Text('Append Widget', textAlign: TextAlign.center),
);
},
),
//builder which return null will not be shown.
SpecialItem(
position: SpecialItemPosition.append,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
return null;
},
),
SpecialItem(
position: SpecialItemPosition.prepend,
builder: (
BuildContext context,
AssetPathEntity? path,
int length,
PermissionState permissionState,
) {
return null;
},
),
],
),
);
},
Expand Down
Loading
Loading