Skip to content

Conversation

shihaohong
Copy link
Contributor

Description

Adds state restoration capabilities to the drawer and endDrawer.

Related Issues

Fixes #70925
Related to #62916

Tests

I added the following tests:

  • Tests to make sure that state restoration is off if Scaffold.restorationId is null.
  • Tests to make sure that state restoration behaves as expected for Scaffold.drawer and Scaffold.endDrawer.

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Dec 22, 2020
@google-cla google-cla bot added the cla: yes label Dec 22, 2020
@shihaohong shihaohong added the a: state restoration RestorationManager and related APIs label Dec 22, 2020
@shihaohong shihaohong changed the title [WIP][State Restoration] Scaffold.drawer and Scaffold.endDrawer [State Restoration] Scaffold.drawer and Scaffold.endDrawer Dec 22, 2020
Comment on lines 336 to 338
if (status == AnimationStatus.completed || status == AnimationStatus.dismissed) {
_restorableAnimationValue.value = _controller.value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just store a bool then to indicate open or closed?

Comment on lines +1792 to +1793
/// The state of this widget is persisted in a [RestorationBucket] claimed
/// from the surrounding [RestorationScope] using the provided restoration ID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true, but it should be :)

Right now, it doesn't use the provided restoration ID and instead uses ${restorationId}_end_drawer and ${restorationId}_drawer.

I think you want ScaffoldState to use the RestorationMixin, which makes it claim a bucket using restorationId. Then you insert that Bucket into the widget hierarchy around the two DrawerController using a UnmanagedRestorationScope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually decided to pull out the restorable drawer open/close states into ScaffoldState, which I think is better because I worry about having two separate drawer open/close states in both the Scaffold and the Drawer widgets not aligning. PTAL and let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. That's even better!

@goderbauer
Copy link
Member

Looks like this is causing some test failures.

@shihaohong
Copy link
Contributor Author

shihaohong commented Jan 7, 2021

Fixed the failing tests. Just needed to make sure to address when isDrawerOpen's value is modified when passed into the DrawerController. Otherwise, it only initializes the DrawerController's value.

Edit: Looks like some other set of tests are now failing. I'll look into it

Edit2: The isDrawerOpen parameter was causing drawers that were mid-animation to snap into place when the _drawerOpened or _endDrawerOpened values were updated in Scaffold. I added a conditional to only update the drawer controller value if the drawer controller is completed or dismissed.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shihaohong shihaohong deleted the state-restorable-drawer branch April 19, 2021 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: state restoration RestorationManager and related APIs f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[State Restoration] Drawer not restorable
3 participants