During state restoration, if I do not have a widget correctly annotated with @pragma('vm:entry-point') I can get the following runtime error:
E/DartVM (16239): ERROR: To access 'package:bible/view/more_screen.dart::MoreScreen' from native code, it must be annotated.
E/DartVM (16239): ERROR: See https://github.com/dart-lang/sdk/blob/master/runtime/docs/compiler/aot/entry_point_pragma.md
This results in the app hanging at start-up with a blank screen. Not good! Killing and restarting the app does not help, as it just tries to restore state again. Since it isn’t actually crashing, the OS doesn’t erase the state and restart the app at the first screen.
Since the above error is in the Dart later, I can’t catch it in Flutter. I have found Android will throw an AssertionError (which I can catch and then call exit) but iOS does not. I’m in the process of writing a watchdog timer that will call exit if the app doesn’t correctly start in 15 seconds.
Has anyone run into anything similar and/or have a better idea of how to approach this?
The issue is that if I miss an annotating a widget the app is trying to restore to, my users get a runtime error, which is only logged to the console, that results in a blank screen on iOS and the app icon on Android. The app is hung. Killing and restarting the app results in the same thing. As far as I can tell deleting and reinstalling the app is the only way to resolve this.
I can fix this widget. But it’s something I’ve repeatedly come across, where I’m testing my app, randomly encounter a hang and only then realize I missed one.
I have to wonder, am I doing something wrong? Is no one else doing state restoration? Is there a navigation/routing package everybody uses that handles it better? Or is everyone muddling through it the way I am?
It appears what triggers this is transitioning from Navigator.push to restorablePush. A restorablePush requires a static route to be defined. If that route is the only place you reference a widget, it will be tree-shaken away unless you annotate it.
I can’t help much there, but just fyi: I tried making state restoration happen myself, and ran into a lot of issues like this with not a lot of documentation around it.
I gave up and implemented a poor man’s version myself for the stuff that I needed.
I am not sure if any large production app actually uses state restoration, I honestly doubt it.
@bruce419 if you have a reproduction (e.g. standalone example which can be compiled and run to demonstrate this behavior) you should file a bug in Flutter issue tracker. It is definitely not a good developer experience.
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape. Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.