diff --git a/CHANGELOG.md b/CHANGELOG.md index a7bd09cc..32465a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example/lib/customs/pickers/directory_file_asset_picker.dart b/example/lib/customs/pickers/directory_file_asset_picker.dart index 60121452..79799faa 100644 --- a/example/lib/customs/pickers/directory_file_asset_picker.dart +++ b/example/lib/customs/pickers/directory_file_asset_picker.dart @@ -381,8 +381,8 @@ class FileAssetPickerBuilder @override Future viewAsset( BuildContext context, - int index, - AssetEntity currentAsset, + int? index, + File currentAsset, ) async { final List? result = await Navigator.of(context).push?>( PageRouteBuilder>( @@ -393,7 +393,8 @@ class FileAssetPickerBuilder ) { return AssetPickerViewer( builder: FileAssetPickerViewerBuilderDelegate( - currentIndex: index, + currentIndex: + index ?? provider.selectedAssets.indexOf(currentAsset), previewAssets: provider.selectedAssets, provider: FileAssetPickerViewerProvider(provider.selectedAssets), themeData: AssetPicker.themeData(themeColor), diff --git a/example/lib/customs/pickers/insta_asset_picker.dart b/example/lib/customs/pickers/insta_asset_picker.dart index d0003572..879fd87d 100644 --- a/example/lib/customs/pickers/insta_asset_picker.dart +++ b/example/lib/customs/pickers/insta_asset_picker.dart @@ -378,9 +378,12 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate { @override Future 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) { diff --git a/guides/migration_guide.md b/guides/migration_guide.md index 6de65974..88720af6 100644 --- a/guides/migration_guide.md +++ b/guides/migration_guide.md @@ -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 @@ -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: diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index 259a43e2..1c03810c 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -242,11 +242,7 @@ abstract class AssetPickerBuilderDelegate { /// Determine how to browse assets in the viewer. /// 定义如何在查看器中浏览资源 - Future viewAsset( - BuildContext context, - int index, - AssetEntity currentAsset, - ); + Future viewAsset(BuildContext context, int? index, Asset currentAsset); /// Yes, the build method. /// 没错,是它是它就是它,我们亲爱的 build 方法~ @@ -870,7 +866,7 @@ class DefaultAssetPickerBuilderDelegate @override Future viewAsset( BuildContext context, - int index, + int? index, AssetEntity currentAsset, ) async { final DefaultAssetPickerProvider provider = @@ -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; @@ -1936,7 +1936,7 @@ class DefaultAssetPickerBuilderDelegate child: Consumer( builder: (context, DefaultAssetPickerProvider p, __) => GestureDetector( onTap: p.isSelectedNotEmpty - ? () => viewAsset(context, 0, p.selectedAssets.first) + ? () => viewAsset(context, null, p.selectedAssets.first) : null, child: Selector( selector: (_, DefaultAssetPickerProvider p) =>