@@ -28,10 +28,7 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
2828 final ReportPop reportPop;
2929 List <NavigatorObserver > observers = [];
3030
31- ModularRouterDelegate (
32- {required this .parser,
33- required this .navigatorKey,
34- required this .reportPop});
31+ ModularRouterDelegate ({required this .parser, required this .navigatorKey, required this .reportPop});
3532
3633 @override
3734 ModularBook ? currentConfiguration;
@@ -70,11 +67,8 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
7067 Future <void > setNewRoutePath (ModularBook book) async {
7168 final disposableRoutes = < ParallelRoute > [];
7269
73- for (var route
74- in currentConfiguration? .routes ?? < ParallelRoute <dynamic >> []) {
75- if (book.routes
76- .indexWhere ((element) => element.uri.path == route.uri.path) ==
77- - 1 ) {
70+ for (var route in currentConfiguration? .routes ?? < ParallelRoute <dynamic >> []) {
71+ if (book.routes.indexWhere ((element) => element.uri.path == route.uri.path) == - 1 ) {
7872 disposableRoutes.add (route);
7973 }
8074 }
@@ -85,10 +79,6 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
8579 for (var disposableRoute in disposableRoutes) {
8680 reportPop.call (disposableRoute);
8781 }
88-
89- final arguments =
90- parser.getArguments ().getOrElse ((l) => ModularArguments .empty ());
91- parser.setArguments (arguments.copyWith (params: {}, data: null ));
9282 }
9383
9484 var _lastClick = DateTime .now ();
@@ -116,37 +106,28 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
116106 final parallel = page.route;
117107 parallel.popCallback? .call (result);
118108 currentConfiguration? .routes.remove (parallel);
119- reportPop.call (parallel);
120- final arguments =
121- parser.getArguments ().getOrElse ((l) => ModularArguments .empty ());
109+ if (currentConfiguration? .routes.indexWhere ((element) => element.uri.toString () == parallel.uri.toString ()) == - 1 ) {
110+ reportPop.call (parallel);
111+ }
112+ final arguments = parser.getArguments ().getOrElse ((l) => ModularArguments .empty ());
122113 parser.setArguments (arguments.copyWith (uri: currentConfiguration! .uri));
123114 notifyListeners ();
124115
125116 return true ;
126117 }
127118
128119 @override
129- Future <T ?> pushNamed <T extends Object ?>(String routeName,
130- {Object ? arguments, bool forRoot = false }) async {
120+ Future <T ?> pushNamed <T extends Object ?>(String routeName, {Object ? arguments, bool forRoot = false }) async {
131121 final popComplete = Completer ();
132- var book = await parser.selectBook (routeName,
133- arguments: arguments, popCallback: popComplete.complete);
122+ var book = await parser.selectBook (routeName, arguments: arguments, popCallback: popComplete.complete);
134123 if (forRoot) {
135- book = currentConfiguration! .copyWith (routes: [
136- ...currentConfiguration! .routes,
137- book.routes.last.copyWith (schema: '' )
138- ]);
124+ book = currentConfiguration! .copyWith (routes: [...currentConfiguration! .routes, book.routes.last.copyWith (schema: '' )]);
139125 await setNewRoutePath (book);
140126 } else {
141127 final list = [...currentConfiguration! .routes];
142128
143129 for (var route in book.routes.reversed) {
144- if (list
145- .firstWhere (
146- (element) => element.uri.toString () == route.uri.toString (),
147- orElse: () => ParallelRoute .empty ())
148- .name ==
149- '' ) {
130+ if (list.firstWhere ((element) => element.uri.toString () == route.uri.toString (), orElse: () => ParallelRoute .empty ()).name == '' ) {
150131 list.add (route);
151132 }
152133 }
@@ -162,31 +143,20 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
162143 }
163144
164145 @override
165- Future <T ?> pushReplacementNamed <T extends Object ?, TO extends Object ?>(
166- String routeName,
167- {TO ? result,
168- Object ? arguments,
169- bool forRoot = false }) async {
146+ Future <T ?> pushReplacementNamed <T extends Object ?, TO extends Object ?>(String routeName, {TO ? result, Object ? arguments, bool forRoot = false }) async {
170147 final popComplete = Completer ();
171- var book = await parser.selectBook (routeName,
172- arguments: arguments, popCallback: popComplete.complete);
148+ var book = await parser.selectBook (routeName, arguments: arguments, popCallback: popComplete.complete);
173149 final currentRoutes = [...currentConfiguration! .routes];
174150 if (forRoot) {
175151 currentRoutes.removeWhere ((element) => element.schema != '' );
176152 currentRoutes.removeLast ();
177- book = currentConfiguration! .copyWith (
178- routes: [...currentRoutes, book.routes.first.copyWith (schema: '' )]);
153+ book = currentConfiguration! .copyWith (routes: [...currentRoutes, book.routes.first.copyWith (schema: '' )]);
179154 await setNewRoutePath (book);
180155 } else {
181156 final list = [...currentConfiguration! .routes]..removeLast ();
182157
183158 for (var route in book.routes.reversed) {
184- if (list
185- .firstWhere (
186- (element) => element.uri.toString () == route.uri.toString (),
187- orElse: () => ParallelRoute .empty ())
188- .name ==
189- '' ) {
159+ if (list.firstWhere ((element) => element.uri.toString () == route.uri.toString (), orElse: () => ParallelRoute .empty ()).name == '' ) {
190160 list.add (route);
191161 }
192162 }
@@ -197,11 +167,7 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
197167 }
198168
199169 @override
200- Future <T ?> popAndPushNamed <T extends Object ?, TO extends Object ?>(
201- String routeName,
202- {TO ? result,
203- Object ? arguments,
204- bool forRoot = false }) {
170+ Future <T ?> popAndPushNamed <T extends Object ?, TO extends Object ?>(String routeName, {TO ? result, Object ? arguments, bool forRoot = false }) {
205171 pop (result);
206172 return pushNamed (routeName, arguments: arguments);
207173 }
@@ -210,20 +176,15 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
210176 bool canPop () => navigatorKey.currentState? .canPop () ?? false ;
211177
212178 @override
213- Future <bool > maybePop <T extends Object ?>([T ? result]) =>
214- navigatorKey.currentState? .maybePop (result) ?? Future .value (false );
179+ Future <bool > maybePop <T extends Object ?>([T ? result]) => navigatorKey.currentState? .maybePop (result) ?? Future .value (false );
215180
216181 @override
217- void pop <T extends Object ?>([T ? result]) =>
218- navigatorKey.currentState? .pop (result);
182+ void pop <T extends Object ?>([T ? result]) => navigatorKey.currentState? .pop (result);
219183
220184 @override
221185 void popUntil (bool Function (Route ) predicate) {
222186 var isFoundedPages = currentConfiguration? .routes.where ((route) {
223- return predicate (CustomModalRoute (ModularPage (
224- route: route,
225- args: ModularArguments .empty (),
226- flags: ModularFlags ())));
187+ return predicate (CustomModalRoute (ModularPage (route: route, args: ModularArguments .empty (), flags: ModularFlags ())));
227188 });
228189
229190 isFoundedPages ?? = [];
@@ -235,9 +196,7 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
235196 }
236197
237198 @override
238- Future <T ?> pushNamedAndRemoveUntil <T extends Object ?>(
239- String newRouteName, bool Function (Route ) predicate,
240- {Object ? arguments, bool forRoot = false }) {
199+ Future <T ?> pushNamedAndRemoveUntil <T extends Object ?>(String newRouteName, bool Function (Route ) predicate, {Object ? arguments, bool forRoot = false }) {
241200 popUntil (predicate);
242201 return pushNamed <T >(newRouteName, arguments: arguments, forRoot: forRoot);
243202 }
@@ -264,8 +223,7 @@ class CustomModalRoute extends ModalRoute {
264223 String ? get barrierLabel => throw UnimplementedError ();
265224
266225 @override
267- Widget buildPage (BuildContext context, Animation <double > animation,
268- Animation <double > secondaryAnimation) {
226+ Widget buildPage (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
269227 throw UnimplementedError ();
270228 }
271229
0 commit comments