Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Conversation

@shihaohong
Copy link

@shihaohong shihaohong commented Dec 16, 2020

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:

Screen Shot 2020-12-16 at 11 35 34 AM

(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:

  1. Open the Gallery app on an Android device
  2. Swipe the carousel to the Shrine app card and tap it.
  3. On the Shrine app home page, kill the activity and reopen the app.

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.dart while on any screen in the gallery results in the following error message:

Unhandled exception:
root::package:gallery/studies/shrine/app.dart::_RestorableAppStateModel::@methods::package:flutter/src/widgets/restoration.dart::_debugAssertNotDisposed is already bound
#0      CanonicalName.bindTo (package:kernel/canonical_name.dart:192:7)
#1      Class.computeCanonicalNames (package:kernel/ast.dart:1201:51)
#2      Library.computeCanonicalNames (package:kernel/ast.dart:559:14)
#3      Component.computeCanonicalNamesForLibrary (package:kernel/ast.dart:10821:13)
#4      Component.computeCanonicalNames (package:kernel/ast.dart:10783:7)
#5      sortComponent (package:vm/kernel_front_end.dart:679:13)
#6      FrontendCompiler.writeDillFile (package:frontend_server/frontend_server.dart:656:5)
#7      FrontendCompiler.recompileDelta (package:frontend_server/frontend_server.dart:766:13)
<asynchronous suspension>

the Dart compiler exited unexpectedly.
Exited (1)

I'm not really sure what's going on. The app works fine otherwise.

child: WillPopScope(
onWillPop: _onWillPop,
child: MaterialApp(
restorationScopeId: 'shrineApp',
Copy link
Author

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.

onGenerateInitialRoutes: (_) {
return [
MaterialPageRoute<void>(
builder: (context) => const LoginPage(),
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

@shihaohong
Copy link
Author

shihaohong commented Dec 17, 2020

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.dart while on any screen in the gallery results in the following error message:

Unhandled exception:
root::package:gallery/studies/shrine/app.dart::_RestorableAppStateModel::@methods::package:flutter/src/widgets/restoration.dart::_debugAssertNotDisposed is already bound
#0      CanonicalName.bindTo (package:kernel/canonical_name.dart:192:7)
#1      Class.computeCanonicalNames (package:kernel/ast.dart:1201:51)
#2      Library.computeCanonicalNames (package:kernel/ast.dart:559:14)
#3      Component.computeCanonicalNamesForLibrary (package:kernel/ast.dart:10821:13)
#4      Component.computeCanonicalNames (package:kernel/ast.dart:10783:7)
#5      sortComponent (package:vm/kernel_front_end.dart:679:13)
#6      FrontendCompiler.writeDillFile (package:frontend_server/frontend_server.dart:656:5)
#7      FrontendCompiler.recompileDelta (package:frontend_server/frontend_server.dart:766:13)
<asynchronous suspension>

the Dart compiler exited unexpectedly.
Exited (1)

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.

@shihaohong shihaohong changed the title WIP - state restoration for shrine app State Restoration for Shrine Dec 17, 2020
@shihaohong
Copy link
Author

Copy link
Member

@guidezpl guidezpl left a 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


@override
Widget build(BuildContext context) {
if (_isExpandingControllerCompleted.value !=
Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

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

@shihaohong
Copy link
Author

shihaohong commented Dec 21, 2020

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.

@shihaohong
Copy link
Author

shihaohong commented Dec 22, 2020

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?

@guidezpl
Copy link
Member

If unrelated, this seems fine to merge

@shihaohong shihaohong merged commit 82a50e7 into flutter:master Dec 24, 2020
@shihaohong shihaohong deleted the state-restorable-shrine branch December 24, 2020 10:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants