-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[State Restoration] Shrine #389
[State Restoration] Shrine #389
Conversation
lib/studies/shrine/app.dart
Outdated
| child: WillPopScope( | ||
| onWillPop: _onWillPop, | ||
| child: MaterialApp( | ||
| restorationScopeId: 'shrineApp', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is shows up with the addition of this line.
lib/studies/shrine/app.dart
Outdated
| onGenerateInitialRoutes: (_) { | ||
| return [ | ||
| MaterialPageRoute<void>( | ||
| builder: (context) => const LoginPage(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that the route(s) returned by onGenerateInitialRoutes do not have Route.settings.name set. This means, they cannot be restored and you end up with an empty set of routes to restore. We should provide a better error here. I'll file an issue for it.
In this case, the fix is really simple: Just remove the onGenerateInitialRoutes argument altogether. The app is already specifying an initialRoute: ShrineApp.loginRoute, which when looked up in the routes table below produces a route with a LoginPage - that's exactly the same thing that onGenerateInitialRoutes is doing. So instead of specifying it, we can just rely on the defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed flutter/flutter#72453.
|
The app seems to be state restorable now. However, I somehow broke hot reload with this PR... Any change in the code for I'm not really sure what's going on. The app works fine otherwise. Edit: I also just realized that the same thing happens for the Reply mini app. |
|
I made a small reproducible test app with the hot reload crash: https://github.com/shihaohong/state_restoration_provider_crash |
guidezpl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ ___ _____ __ __
| | / __|_ _| \/ |
| |_| (_ | | | | |\/| |
|____\___| |_| |_| |_|
Merging should be held pending the hot reload crash fix
lib/studies/shrine/app.dart
Outdated
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| if (_isExpandingControllerCompleted.value != |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a statusListener for this feels a bit clunky. Could there be a cleaner way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about this too... Let me see if I can come up with a better API for this, here and everywhere else tab controller is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored this out into its own class here: https://github.com/flutter/gallery/pull/389/files#diff-4576115e6281d08372fae69eebb7d35cff0bc534481112f35d3825370064b6abR32
Let me know what you think or if you have any improvement suggestions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! For clarity, I wonder if setAnimationController would be better named as registerStatusListener or something similar
|
Filed an issue at dart-lang/sdk#44523 and flutter/flutter#72700 about the hot reload crash. We'll see what the Dart folks say and see if they can identify the root cause. |
|
According to flutter/flutter#72700 (comment), this seems like a Dart issue unrelated to state restoration. Should we still hold off until that issue is fixed before moving forward with this PR? |
|
If unrelated, this seems fine to merge |
Description
Adds State Restoration for Shrine mini app.
Bumps along the way (Documenting here)
Routes issue
/cc @goderbauer I'm not sure what's the problem here and I was debugging this for quite a while, but every time I try to restore the Shrine mini app, I get the following error message:

(had to use a screenshot because VSCode is giving me trouble with highlighting/copy-pasting the error)Some of the lines may be a little off because I put some print statements in to try and debug and am quite lost. The setup of this app is similar to the Reply app, so I'm surprised that this one is acting up in this way. Any ideas?
To reproduce:
Hot reload issue
The app seems to be state restorable now. However, I somehow broke hot reload with this PR... Any change in the code for
gallery/studies/shrine/app.dartwhile on any screen in the gallery results in the following error message:I'm not really sure what's going on. The app works fine otherwise.