@@ -39,9 +39,9 @@ enum ContainerLifeCycle {
3939}
4040
4141typedef BoostContainerLifeCycleObserver = void Function (
42- ContainerLifeCycle state,
43- BoostContainerSettings settings,
44- );
42+ ContainerLifeCycle state,
43+ BoostContainerSettings settings,
44+ );
4545
4646class BoostContainer extends Navigator {
4747 const BoostContainer ({
@@ -52,17 +52,17 @@ class BoostContainer extends Navigator {
5252 RouteFactory onUnknownRoute,
5353 List <NavigatorObserver > observers,
5454 }) : super (
55- key: key,
56- initialRoute: initialRoute,
57- onGenerateRoute: onGenerateRoute,
58- onUnknownRoute: onUnknownRoute,
59- observers: observers,
60- );
55+ key: key,
56+ initialRoute: initialRoute,
57+ onGenerateRoute: onGenerateRoute,
58+ onUnknownRoute: onUnknownRoute,
59+ observers: observers,
60+ );
6161
6262 factory BoostContainer .copy (
63- Navigator navigator, [
64- BoostContainerSettings settings = const BoostContainerSettings (),
65- ]) =>
63+ Navigator navigator, [
64+ BoostContainerSettings settings = const BoostContainerSettings (),
65+ ]) =>
6666 BoostContainer (
6767 key: GlobalKey <BoostContainerState >(),
6868 settings: settings,
@@ -73,9 +73,9 @@ class BoostContainer extends Navigator {
7373 );
7474
7575 factory BoostContainer .obtain (
76- Navigator navigator,
77- BoostContainerSettings settings,
78- ) =>
76+ Navigator navigator,
77+ BoostContainerSettings settings,
78+ ) =>
7979 BoostContainer (
8080 key: GlobalKey <BoostContainerState >(),
8181 settings: settings,
@@ -110,18 +110,20 @@ class BoostContainer extends Navigator {
110110
111111 static BoostContainerState tryOf (BuildContext context) {
112112 final BoostContainerState container =
113- context.findAncestorStateOfType <BoostContainerState >();
113+ context.findAncestorStateOfType <BoostContainerState >();
114114 return container;
115115 }
116116
117117 static BoostContainerState of (BuildContext context) {
118118 final BoostContainerState container =
119- context.findAncestorStateOfType <BoostContainerState >();
119+ context.findAncestorStateOfType <BoostContainerState >();
120120 assert (container != null , 'not in flutter boost' );
121121 return container;
122122 }
123123
124124 String desc () => '{uniqueId=${settings .uniqueId },name=${settings .name }}' ;
125+
126+ RouteListFactory get initialRoutes => super .onGenerateInitialRoutes;
125127}
126128
127129class BoostContainerState extends NavigatorState {
@@ -161,6 +163,15 @@ class BoostContainerState extends NavigatorState {
161163 void initState () {
162164 super .initState ();
163165 backPressedHandler = () => maybePop ();
166+ final String initRoute = widget.initialRoute ?? Navigator .defaultRouteName;
167+ if (initRoute != null && routerHistory.isEmpty) {
168+ routerHistory.addAll (
169+ widget.initialRoutes (
170+ this ,
171+ widget.initialRoute ?? Navigator .defaultRouteName
172+ )
173+ );
174+ }
164175 }
165176
166177 @override
@@ -177,22 +188,28 @@ class BoostContainerState extends NavigatorState {
177188
178189 @override
179190 Future <bool > maybePop <T extends Object >([T result]) async {
191+ if (routerHistory.isEmpty) {
192+ pop (result);
193+ return true ;
194+ }
195+
180196 final Route <T > route = routerHistory.last as Route <T >;
197+
181198 final RoutePopDisposition disposition = await route.willPop ();
182199 if (mounted) {
183- switch (disposition) {
184- case RoutePopDisposition .pop:
185- pop (result);
186- return true ;
187- break ;
188- case RoutePopDisposition .doNotPop:
189- return false ;
190- break ;
191- case RoutePopDisposition .bubble:
192- pop (result);
193- return true ;
194- break ;
195- }
200+ switch (disposition) {
201+ case RoutePopDisposition .pop:
202+ pop (result);
203+ return true ;
204+ break ;
205+ case RoutePopDisposition .doNotPop:
206+ return false ;
207+ break ;
208+ case RoutePopDisposition .bubble:
209+ pop (result);
210+ return true ;
211+ break ;
212+ }
196213 }
197214 return false ;
198215 }
@@ -238,10 +255,10 @@ class BoostContainerState extends NavigatorState {
238255
239256 VoidCallback addLifeCycleObserver (BoostContainerLifeCycleObserver observer) {
240257 return FlutterBoost .singleton.addBoostContainerLifeCycleObserver (
241- (
242- ContainerLifeCycle state,
243- BoostContainerSettings settings,
244- ) {
258+ (
259+ ContainerLifeCycle state,
260+ BoostContainerSettings settings,
261+ ) {
245262 if (settings.uniqueId == uniqueId) {
246263 observer (state, settings);
247264 }
0 commit comments