Skip to content

Commit 34841fa

Browse files
authored
🐛 Fix keep offset jumping recovery issues (#174)
1 parent ec3f343 commit 34841fa

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
188188
/// Be aware that the method will do nothing when [keepScrollOffset] is true.
189189
/// 注意当 [keepScrollOffset] 为 true 时方法不会进行释放。
190190
void dispose() {
191-
if (keepScrollOffset) {
192-
return;
193-
}
191+
Constants.scrollPosition = null;
194192
gridScrollController.dispose();
195193
permission.dispose();
196194
permissionOverlayHidden.dispose();
@@ -586,11 +584,12 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
586584
Widget build(BuildContext context) {
587585
// Schedule the scroll position's restoration callback if this feature
588586
// is enabled and offsets are different.
589-
if (keepScrollOffset &&
590-
Constants.scrollPosition != null &&
591-
!gridScrollController.hasClients) {
587+
if (keepScrollOffset && Constants.scrollPosition != null) {
592588
SchedulerBinding.instance!.addPostFrameCallback((_) {
593-
gridScrollController.jumpTo(Constants.scrollPosition!.pixels);
589+
// Update only if the controller has clients.
590+
if (gridScrollController.hasClients) {
591+
gridScrollController.jumpTo(Constants.scrollPosition!.pixels);
592+
}
594593
});
595594
}
596595
return AnnotatedRegion<SystemUiOverlayStyle>(

lib/src/widget/asset_picker.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ class AssetPickerState<Asset, Path> extends State<AssetPicker<Asset, Path>>
262262
void dispose() {
263263
WidgetsBinding.instance!.removeObserver(this);
264264
AssetPicker.unregisterObserve(_onLimitedAssetsUpdated);
265-
widget.builder.dispose();
265+
// Skip delegate's dispose when it's keeping scroll offset.
266+
if (!widget.builder.keepScrollOffset) {
267+
widget.builder.dispose();
268+
}
266269
super.dispose();
267270
}
268271

0 commit comments

Comments
 (0)