auto_route_library
auto_route_library copied to clipboard
Blinking on change routerConfig
Hi and thanks for the great package!
I noticed blinking the screen when I change the routerConfig
in the MaterialApp.router
.
https://github.com/user-attachments/assets/3f8c831e-048d-45f1-af47-4cf1c47fe54a
Here is the code of the app
`main.dart`
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'router1.dart';
import 'router2.dart';
final _routers = <RootStackRouter>[
Router1(),
Router2(),
];
void main()
{
runApp(const App());
}
class App extends StatefulWidget
{
const App({super.key});
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App>
{
@override
void initState()
{
super.initState();
Future.delayed(const Duration(seconds: 2), () => setState(() {
if (++_router >= _routers.length) _router = 0;
}));
}
@override
Widget build(final BuildContext context) {
return MaterialApp.router(
title: 'Flutter Demo',
theme: ThemeData(useMaterial3: true),
routerConfig: _routers[_router].config(),
);
}
var _router = 0;
}
`router1.dart`
import 'package:auto_route/auto_route.dart';
import 'home_page.dart';
class Router1 extends RootStackRouter
{
@override
List<AutoRoute> get routes => [
AutoRoute(path: '/', page: HomeRoute.page),
];
}
class HomeRoute extends PageRouteInfo<void>
{
const HomeRoute({ final List<PageRouteInfo>? children })
: super(
HomeRoute.name,
initialChildren: children,
);
static const name = 'HomeRoute';
static final page = PageInfo(
name,
builder: (data) {
return const HomePage(title: 'Page 1');
},
);
}
`router2.dart`
import 'package:auto_route/auto_route.dart';
import 'home_page.dart';
class Router2 extends RootStackRouter
{
@override
List<AutoRoute> get routes => [
AutoRoute(path: '/', page: HomeRoute.page),
];
}
class HomeRoute extends PageRouteInfo<void>
{
const HomeRoute({ final List<PageRouteInfo>? children })
: super(
HomeRoute.name,
initialChildren: children,
);
static const name = 'HomeRoute';
static final page = PageInfo(
name,
builder: (data) {
return const HomePage(title: 'Page 2');
},
);
}
`home_page.dart`
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget
{
final String title;
const HomePage({ super.key, required this.title });
@override
Widget build(final BuildContext context)
{
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(title),
),
);
}
}
There is no blinking with go_router
or some other navigation packages. Could you please check what is the reason and how to avoid this behavior? Thanks.