@@ -11,24 +11,24 @@ void main() {
1111
1212final class HomeRouteState extends RouteState {
1313 HomeRouteState ()
14- : super .parse (
15- '/home' ,
16- // Use QuickForwardtEffect() as the default transtion effect for this
17- // route. This can be overridden when pushing this route.
18- animationEffect: const ForwardEffectWeb (),
19- );
14+ : super .parse (
15+ '/home' ,
16+ // Use QuickForwardtEffect() as the default transtion effect for this
17+ // route. This can be overridden when pushing this route.
18+ animationEffect: const ForwardEffectWeb (),
19+ );
2020}
2121
2222// This route is only used in the RouteManager, so it does not need to
2323// be pushed directly. It is a base route for the chat feature.
2424final class BaseChatRouteState extends RouteState {
2525 BaseChatRouteState ({Map <String , String >? queryParameters})
26- : super .parse (
27- '/chat' ,
28- queryParameters: queryParameters,
29- // Use a different animation effect for this route.
30- animationEffect: const SlideDownEffect (),
31- );
26+ : super .parse (
27+ '/chat' ,
28+ queryParameters: queryParameters,
29+ // Use a different animation effect for this route.
30+ animationEffect: const SlideDownEffect (),
31+ );
3232
3333 BaseChatRouteState .from (RouteState other) : super (other.uri);
3434}
@@ -37,11 +37,11 @@ final class ChatRouteState extends BaseChatRouteState {
3737 final String chatId;
3838
3939 ChatRouteState ({required this .chatId})
40- : super (queryParameters: {'chatId' : chatId});
40+ : super (queryParameters: {'chatId' : chatId});
4141
4242 ChatRouteState .from (super .other)
43- : chatId = other.uri.queryParameters['chatId' ] ?? '' ,
44- super .from ();
43+ : chatId = other.uri.queryParameters['chatId' ] ?? '' ,
44+ super .from ();
4545}
4646
4747class MyApp extends StatelessWidget {
@@ -50,32 +50,41 @@ class MyApp extends StatelessWidget {
5050 @override
5151 Widget build (BuildContext context) {
5252 return MaterialApp (
53- //home: // Do not use "home", as it conflicts with RouteManager. Use
54- // "builder" instead.
55- builder: (context, child) {
56- return RouteManager (
57- fallbackRouteState: () => HomeRouteState (),
58- builders: [
59- RouteBuilder (
60- routeState: HomeRouteState (),
61- // Pre-build the HomeScreen even if the initial route is not
62- // HomeRouteState. This is useful for performance optimization.
63- shouldPrebuild: true ,
64- // Preserve the HomeScreen widget to avoid rebuilding it.
65- shouldPreserve: true ,
66- builder: (context, routeState) =>
67- HomeScreen (routeState: HomeRouteState ()),
68- ),
69- RouteBuilder (
70- // Use the BaseChatRouteState instead of the ChatRouteState
71- // since it does not require a chatId to be pushed.
72- routeState: BaseChatRouteState (),
73- builder: (context, routeState) =>
74- ChatScreen (routeState: ChatRouteState .from (routeState)),
53+ home: Material (
54+ type: MaterialType .transparency,
55+ child: Overlay (
56+ initialEntries: [
57+ OverlayEntry (
58+ maintainState: true ,
59+ builder: (context) {
60+ return RouteManager (
61+ fallbackRouteState: () => HomeRouteState (),
62+ builders: [
63+ RouteBuilder (
64+ routeState: HomeRouteState (),
65+ // Pre-build the HomeScreen even if the initial route is not
66+ // HomeRouteState. This is useful for performance optimization.
67+ shouldPrebuild: true ,
68+ // Preserve the HomeScreen widget to avoid rebuilding it.
69+ shouldPreserve: true ,
70+ builder: (context, routeState) =>
71+ HomeScreen (routeState: HomeRouteState ()),
72+ ),
73+ RouteBuilder (
74+ // Use the BaseChatRouteState instead of the ChatRouteState
75+ // since it does not require a chatId to be pushed.
76+ routeState: BaseChatRouteState (),
77+ builder: (context, routeState) => ChatScreen (
78+ routeState: ChatRouteState .from (routeState),
79+ ),
80+ ),
81+ ],
82+ );
83+ },
7584 ),
7685 ],
77- );
78- } ,
86+ ),
87+ ) ,
7988 );
8089 }
8190}
@@ -127,14 +136,14 @@ class ChatScreen extends StatelessWidget with RouteWidgetMixin {
127136 ElevatedButton (
128137 onPressed: () {
129138 final controller = RouteController .of (context);
130- controller.pushBack ();
139+ controller.goBack ();
131140 },
132141 child: const Text ('Go Back - Default Effect' ),
133142 ),
134143 ElevatedButton (
135144 onPressed: () {
136145 final controller = RouteController .of (context);
137- controller.pushBack (animationEffect: const BackwardEffectWeb ());
146+ controller.goBack (animationEffect: const BackwardEffectWeb ());
138147 },
139148 child: const Text ('Go Back - Quick Back Effect' ),
140149 ),
0 commit comments