Skip to content

Commit

Permalink
Merge branch 'main' into fix/use-permission-request-options
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Feb 6, 2024
2 parents 3aaf458 + eaab93c commit 7779040
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ that can be found in the LICENSE file. -->

### Fixes

- Fix previewing selected assets behavior.
- Use `PermissionRequestOption` as much as possible.

## 9.0.0-dev.2
Expand Down
7 changes: 4 additions & 3 deletions example/lib/customs/pickers/directory_file_asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ class FileAssetPickerBuilder
@override
Future<void> viewAsset(
BuildContext context,
int index,
AssetEntity currentAsset,
int? index,
File currentAsset,
) async {
final List<File>? result = await Navigator.of(context).push<List<File>?>(
PageRouteBuilder<List<File>>(
Expand All @@ -393,7 +393,8 @@ class FileAssetPickerBuilder
) {
return AssetPickerViewer<File, Directory>(
builder: FileAssetPickerViewerBuilderDelegate(
currentIndex: index,
currentIndex:
index ?? provider.selectedAssets.indexOf(currentAsset),
previewAssets: provider.selectedAssets,
provider: FileAssetPickerViewerProvider(provider.selectedAssets),
themeData: AssetPicker.themeData(themeColor),
Expand Down
5 changes: 4 additions & 1 deletion example/lib/customs/pickers/insta_asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,12 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
@override
Future<void> viewAsset(
BuildContext context,
int index,
int? index,
AssetEntity currentAsset,
) async {
if (index == null) {
return;
}
// if is preview asset, unselect it
if (provider.selectedAssets.isNotEmpty &&
_previewAsset.value == currentAsset) {
Expand Down
11 changes: 9 additions & 2 deletions guides/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ This document gathered all breaking changes and migrations requirement between m

## 9.0.0

### Summary
### View assets signature change

`AssetPickerBuilderDelegate.viewAsset` has 2 changes:
- It now uses the generic type of the delegate rather than always `AssetEntity`.
- The `index` of arguments is now nullable,
to indicate the behavior of previewing selected assets only.

### Permission request option integration

`PermissionRequestOption` has been added to
`AssetPickerDelegate.permissionCheck` and
Expand All @@ -28,7 +35,7 @@ Classes that extend `AssetPickerDelegate` and override these methods must migrat
Delegates that use `AssetPicker.permissionCheck`
should choose whether to pass the request option.

### Details
#### Details

Before:

Expand Down
14 changes: 7 additions & 7 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {

/// Determine how to browse assets in the viewer.
/// 定义如何在查看器中浏览资源
Future<void> viewAsset(
BuildContext context,
int index,
AssetEntity currentAsset,
);
Future<void> viewAsset(BuildContext context, int? index, Asset currentAsset);

/// Yes, the build method.
/// 没错,是它是它就是它,我们亲爱的 build 方法~
Expand Down Expand Up @@ -870,7 +866,7 @@ class DefaultAssetPickerBuilderDelegate
@override
Future<void> viewAsset(
BuildContext context,
int index,
int? index,
AssetEntity currentAsset,
) async {
final DefaultAssetPickerProvider provider =
Expand Down Expand Up @@ -902,6 +898,10 @@ class DefaultAssetPickerBuilderDelegate
selected = provider.selectedAssets;
effectiveIndex = current.indexOf(currentAsset);
}
} else if (index == null) {
current = provider.selectedAssets;
selected = provider.selectedAssets;
effectiveIndex = selected.indexOf(currentAsset);
} else {
current = provider.currentAssets;
selected = provider.selectedAssets;
Expand Down Expand Up @@ -1936,7 +1936,7 @@ class DefaultAssetPickerBuilderDelegate
child: Consumer<DefaultAssetPickerProvider>(
builder: (context, DefaultAssetPickerProvider p, __) => GestureDetector(
onTap: p.isSelectedNotEmpty
? () => viewAsset(context, 0, p.selectedAssets.first)
? () => viewAsset(context, null, p.selectedAssets.first)
: null,
child: Selector<DefaultAssetPickerProvider, String>(
selector: (_, DefaultAssetPickerProvider p) =>
Expand Down

0 comments on commit 7779040

Please sign in to comment.