You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[go_router] Figure out how to deal with inline GoRouter creation in MaterialApp.router #127206
Which would lose the state every time MyWidget is rebuilt.
Proposal
We should figure out how to avoid this situation. One idea can be writing a lint to warn user and advise putting the goRouter into a permanent variable
Reacted by fabiancrx, Andrea Bizzotto, Anton Stubenbord, Sven Gasterstädt, Žiga Povhe, Venkatesan, Memorias de un informático (Lorenzo), Bruno, Hannah Jin, Igor Shtein and 1 more
I have personally not had to experience this; I came across this while reading Andrea's article.
So my question is, What if it was a final variable in a class?
classAppRouter {
final router =GoRouter();
}
And then:
classMyWidgetextendsStatelessWidget {
@overrideWidgetbuild(context) {
// This could also be a state variable if MyWidget was a stateful widgetfinal appRouter =AppRouter();
returnMaterialApp.router(routerConfig: appRouter.router);
}
}
Activity
bizz84 commentedon Jun 18, 2023
@chunhtai I got bitten by this also. I think having a linter rule for this would be a great step forward. 👍
davidnwaneri commentedon Aug 29, 2023
A question.
I have personally not had to experience this; I came across this while reading Andrea's article.
So my question is, What if it was a final variable in a class?
And then:
chunhtai commentedon Aug 29, 2023
@davidnwaneri
Unless it is a static variable, it would still be recreated when the
buildmethod is called.test: guard inline config() through a hot reload (flutter/flutter#127206