Closed AlexShniperson-INO closed 2 years ago
I think this is a covert bug in AutoRoute
, lifecycle
does't use any Key
or WillPopScope
in source code yet AutoRoute
does it.
Check your code where AutoRoute
initialized, or post it here and i'll try to analyze it. 😄
here is example, try to navigate to DetailScreen by clicking Next page
button
https://github.com/AlexShniperson-INO/lifecycle-with-autoroute
it doesn't help, try to play with that project
If i use an instance of NavigatorObserver
, it can trigger this issue.
class MainApp extends StatelessWidget {
final _appRouter = AppRouter(_navigatorKey);
final _observer = NavigatorObserver();
MainApp({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerDelegate: AutoRouterDelegate(
_appRouter,
navigatorObservers: () => [_observer],
),
routeInformationParser: _appRouter.defaultRouteParser(),
);
}
}
But use a new instance every time is ok:
class MainApp extends StatelessWidget {
final _appRouter = AppRouter(_navigatorKey);
MainApp({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerDelegate: AutoRouterDelegate(
_appRouter,
navigatorObservers: () => [NavigatorObserver()],
),
routeInformationParser: _appRouter.defaultRouteParser(),
);
}
}
And replace it to LifecycleObserver()
is fine too.
class MainApp extends StatelessWidget {
final _appRouter = AppRouter(_navigatorKey);
MainApp({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerDelegate: AutoRouterDelegate(
_appRouter,
navigatorObservers: () => [LifecycleObserver()],
),
routeInformationParser: _appRouter.defaultRouteParser(),
);
}
}
You can open an issue for AutoRoute
. 😢
hmm yes i see a new instance is working fine.
this is apparently some kind of auto_route
weirdness.
thank you for help
this works
class MainApp extends StatelessWidget {
final _appRouter = AppRouter();
final _observer = LifecycleObserver();
MainApp({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerDelegate: AutoRouterDelegate(
_appRouter,
navigatorObservers: () => [_observer],
),
routeInformationParser: _appRouter.defaultRouteParser(),
);
}
}
Hi
When i try to use
defaultLifecycleObserver
with AutoRoute i got exception when navigate to other Routedo you have any explanation how to fix that?