From 263db784827e6d909777abcc8add1bcb262d3c55 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 7 Mar 2024 18:35:28 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20current=20asset=20in=20the?= =?UTF-8?q?=20picker=20viewer=20(#561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #560 --- CHANGELOG.md | 4 ++++ .../asset_picker_viewer_builder_delegate.dart | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ffb846..6e58d033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ that can be found in the LICENSE file. --> ## 9.0.1 +### Fixes + +- Fix current asset in the picker viewer. + ### Improvements - Improve code formatting. diff --git a/lib/src/delegates/asset_picker_viewer_builder_delegate.dart b/lib/src/delegates/asset_picker_viewer_builder_delegate.dart index e73effee..a146984c 100644 --- a/lib/src/delegates/asset_picker_viewer_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_viewer_builder_delegate.dart @@ -132,7 +132,11 @@ abstract class AssetPickerViewerBuilderDelegate { /// Getter for the current asset. /// 当前资源的Getter - Asset get currentAsset => previewAssets.elementAt(currentIndex); + Asset get currentAsset => previewAssets.elementAt( + shouldReversePreview + ? previewAssets.length - currentIndex - 1 + : currentIndex, + ); /// Height for bottom preview widget. /// 底栏预览部件的高度 @@ -890,7 +894,10 @@ class DefaultAssetPickerViewerBuilderDelegate initialData: currentIndex, stream: pageStreamController.stream, builder: (_, s) { - final AssetEntity asset = previewAssets.elementAt(s.data!); + final index = s.data!; + final AssetEntity asset = previewAssets.elementAt( + shouldReversePreview ? previewAssets.length - index - 1 : index, + ); return Selector, List>( selector: (_, p) => p.currentlySelectedAssets,