Skip to content

🐛 Fix keep offset jumping recovery issues #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
/// Be aware that the method will do nothing when [keepScrollOffset] is true.
/// 注意当 [keepScrollOffset] 为 true 时方法不会进行释放。
void dispose() {
if (keepScrollOffset) {
return;
}
Constants.scrollPosition = null;
gridScrollController.dispose();
permission.dispose();
permissionOverlayHidden.dispose();
Expand Down Expand Up @@ -586,11 +584,12 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
Widget build(BuildContext context) {
// Schedule the scroll position's restoration callback if this feature
// is enabled and offsets are different.
if (keepScrollOffset &&
Constants.scrollPosition != null &&
!gridScrollController.hasClients) {
if (keepScrollOffset && Constants.scrollPosition != null) {
SchedulerBinding.instance!.addPostFrameCallback((_) {
gridScrollController.jumpTo(Constants.scrollPosition!.pixels);
// Update only if the controller has clients.
if (gridScrollController.hasClients) {
gridScrollController.jumpTo(Constants.scrollPosition!.pixels);
}
});
}
return AnnotatedRegion<SystemUiOverlayStyle>(
Expand Down
5 changes: 4 additions & 1 deletion lib/src/widget/asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ class AssetPickerState<Asset, Path> extends State<AssetPicker<Asset, Path>>
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
AssetPicker.unregisterObserve(_onLimitedAssetsUpdated);
widget.builder.dispose();
// Skip delegate's dispose when it's keeping scroll offset.
if (!widget.builder.keepScrollOffset) {
widget.builder.dispose();
}
super.dispose();
}

Expand Down