Skip to content

Commit

Permalink
🐛 Fix the experience with shouldRevertGrid (fluttercandies#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Feb 26, 2024
1 parent dec7f51 commit e657ca4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ that can be found in the LICENSE file. -->

### Fixes

- Fix previewing selected assets behavior.
- Fix previewing selected assets' behavior.
- Use `PermissionRequestOption` as much as possible.
- Raise more errors for non-synced paths.
- Fix the experience with `shouldRevertGrid`.

## 9.0.0-dev.2

Expand Down
2 changes: 1 addition & 1 deletion lib/src/constants/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
import 'package:photo_manager/photo_manager.dart' show PermissionState;
import 'package:provider/provider.dart';

/// {@nodoc}
/// Mirroring [ChangeNotifierProvider].
typedef CNP<T extends ChangeNotifier?> = ChangeNotifierProvider<T>;

/// {@template wechat_assets_picker.LoadingIndicatorBuilder}
Expand Down
10 changes: 7 additions & 3 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,8 @@ class DefaultAssetPickerBuilderDelegate
provider.selectedAssets.isNotEmpty)) {
return;
}
final List<AssetEntity> current;
final revert = effectiveShouldRevertGrid(context);
List<AssetEntity> current;
final List<AssetEntity>? selected;
final int effectiveIndex;
if (isWeChatMoment) {
Expand All @@ -905,7 +906,10 @@ class DefaultAssetPickerBuilderDelegate
} else {
current = provider.currentAssets;
selected = provider.selectedAssets;
effectiveIndex = index;
effectiveIndex = revert ? current.length - index - 1 : index;
}
if (revert && index == null) {
current = current.reversed.toList(growable: false);
}
final List<AssetEntity>? result = await AssetPickerViewer.pushToViewer(
context,
Expand All @@ -918,7 +922,7 @@ class DefaultAssetPickerBuilderDelegate
selectorProvider: provider,
specialPickerType: specialPickerType,
maxAssets: provider.maxAssets,
shouldReversePreview: isAppleOS(context),
shouldReversePreview: revert,
);
if (result != null) {
Navigator.of(context).maybePop(result);
Expand Down
10 changes: 7 additions & 3 deletions lib/src/delegates/asset_picker_viewer_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ class DefaultAssetPickerViewerBuilderDelegate

@override
Widget assetPageBuilder(BuildContext context, int index) {
final AssetEntity asset = previewAssets.elementAt(index);
final AssetEntity asset = previewAssets.elementAt(
shouldReversePreview ? previewAssets.length - index - 1 : index,
);
final Widget builder = switch (asset.type) {
AssetType.audio => AudioPageBuilder(asset: asset),
AssetType.image => ImagePageBuilder(
Expand Down Expand Up @@ -634,7 +636,10 @@ class DefaultAssetPickerViewerBuilderDelegate
stream: pageStreamController.stream,
builder: (_, AsyncSnapshot<int> snapshot) {
final AssetEntity asset = selectedAssets!.elementAt(index);
final bool isViewing = previewAssets[snapshot.data!] == asset;
final viewingIndex = shouldReversePreview
? previewAssets.length - snapshot.data! - 1
: snapshot.data!;
final bool isViewing = previewAssets[viewingIndex] == asset;
final Widget item = switch (asset.type) {
AssetType.image => _imagePreviewItem(asset),
AssetType.video => _videoPreviewItem(asset),
Expand Down Expand Up @@ -930,7 +935,6 @@ class DefaultAssetPickerViewerBuilderDelegate
controller: pageController,
itemCount: previewAssets.length,
itemBuilder: assetPageBuilder,
reverse: shouldReversePreview,
onPageChanged: (int index) {
currentIndex = index;
pageStreamController.add(index);
Expand Down

0 comments on commit e657ca4

Please sign in to comment.