Skip to content

Commit

Permalink
🐛 Fix index reverting in viewAsset (#570)
Browse files Browse the repository at this point in the history
Fixes #569
  • Loading branch information
AlexV525 authored Apr 8, 2024
1 parent 717488e commit cd20f2f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ that can be found in the LICENSE file. -->
> [!IMPORTANT]
> See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.
## 9.0.3

### Fixes

- Fix index reverting in `viewAsset`.

## 9.0.2

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wechat_assets_picker_demo
description: The demo project for the wechat_assets_picker package.
version: 9.0.2+51
version: 9.0.3+52
publish_to: none

environment:
Expand Down
44 changes: 24 additions & 20 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -869,18 +869,16 @@ class DefaultAssetPickerBuilderDelegate
int? index,
AssetEntity currentAsset,
) async {
final DefaultAssetPickerProvider provider =
context.read<DefaultAssetPickerProvider>();
final p = context.read<DefaultAssetPickerProvider>();
// - When we reached the maximum select count and the asset is not selected,
// do nothing.
// - When the special type is WeChat Moment, pictures and videos cannot
// be selected at the same time. Video select should be banned if any
// pictures are selected.
if ((!provider.selectedAssets.contains(currentAsset) &&
provider.selectedMaximumAssets) ||
if ((!p.selectedAssets.contains(currentAsset) && p.selectedMaximumAssets) ||
(isWeChatMoment &&
currentAsset.type == AssetType.video &&
provider.selectedAssets.isNotEmpty)) {
p.selectedAssets.isNotEmpty)) {
return;
}
final revert = effectiveShouldRevertGrid(context);
Expand All @@ -893,23 +891,29 @@ class DefaultAssetPickerBuilderDelegate
selected = null;
effectiveIndex = 0;
} else {
current = provider.currentAssets
if (index == null) {
current = p.selectedAssets;
current = current.reversed.toList(growable: false);
} else {
current = p.currentAssets;
}
current = current
.where((AssetEntity e) => e.type == AssetType.image)
.toList();
selected = provider.selectedAssets;
effectiveIndex = current.indexOf(currentAsset);
selected = p.selectedAssets;
final i = current.indexOf(currentAsset);
effectiveIndex = revert ? current.length - i - 1 : i;
}
} else if (index == null) {
current = provider.selectedAssets;
selected = provider.selectedAssets;
effectiveIndex = selected.indexOf(currentAsset);
} else {
current = provider.currentAssets;
selected = provider.selectedAssets;
effectiveIndex = revert ? current.length - index - 1 : index;
}
if (revert && index == null) {
current = current.reversed.toList(growable: false);
selected = p.selectedAssets;
if (index == null) {
current = p.selectedAssets;
current = current.reversed.toList(growable: false);
effectiveIndex = selected.indexOf(currentAsset);
} else {
current = p.currentAssets;
effectiveIndex = revert ? current.length - index - 1 : index;
}
}
final List<AssetEntity>? result = await AssetPickerViewer.pushToViewer(
context,
Expand All @@ -919,9 +923,9 @@ class DefaultAssetPickerBuilderDelegate
previewThumbnailSize: previewThumbnailSize,
selectPredicate: selectPredicate,
selectedAssets: selected,
selectorProvider: provider,
selectorProvider: p,
specialPickerType: specialPickerType,
maxAssets: provider.maxAssets,
maxAssets: p.maxAssets,
shouldReversePreview: revert,
);
if (result != null) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wechat_assets_picker
version: 9.0.2
version: 9.0.3
description: |
An image picker (also with videos and audio)
for Flutter projects based on WeChat's UI,
Expand Down

0 comments on commit cd20f2f

Please sign in to comment.