1010// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
1111//.title~
1212
13- // ignore_for_file: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
13+ import 'package:df_log/df_log.dart' ;
14+ import 'package:flutter/widgets.dart' ;
1415
16+ import 'package:df_pod/df_pod.dart' ;
1517import 'package:df_pwa_utils/df_pwa_utils.dart' ;
16- import 'package:df_widgets/_common.dart' ;
1718
1819import '_src.g.dart' ;
1920
@@ -24,9 +25,8 @@ class RouteController {
2425 //
2526 //
2627
27- // TODO: Convert to Pod once that flashing error is fixed.
28- final _pRouteState = ValueNotifier (RouteState .parse ('/' ));
29- ValueListenable <RouteState > get pRouteState => _pRouteState;
28+ final _pRouteState = Pod (RouteState .parse ('/' ));
29+ GenericPod <RouteState > get pRouteState => _pRouteState;
3030 RouteState get routeState => _pRouteState.value;
3131
3232 final _widgetCache = < RouteState , Widget > {};
@@ -36,10 +36,11 @@ class RouteController {
3636 late RouteState _prevRouteState = _pRouteState.value;
3737 final RouteState Function ()? errorRouteState;
3838 final RouteState Function () fallbackRouteState;
39+
3940 RouteState ? _requested;
4041 RouteState ? get requested => _requested;
4142
42- AnimationEffect nextEffect = const NoEffect ();
43+ AnimationEffect _nextEffect = const NoEffect ();
4344
4445 //
4546 //
@@ -55,17 +56,15 @@ class RouteController {
5556 // Set all the builder output to SizedBox.shrink.
5657 resetState ();
5758 _requested = current;
58- final routeState =
59- initialRouteState? .call () ?? _requested ?? fallbackRouteState ();
59+ final routeState = initialRouteState? .call () ?? _requested ?? fallbackRouteState ();
6060 push (routeState);
6161 }
6262
6363 //
6464 //
6565 //
6666
67- RouteState getNavigatorOrFallbackRouteState () =>
68- _requested ?? fallbackRouteState ();
67+ RouteState getNavigatorOrFallbackRouteState () => _requested ?? fallbackRouteState ();
6968
7069 //
7170 //
@@ -76,9 +75,7 @@ class RouteController {
7675 if (url == null ) {
7776 return null ;
7877 }
79- return _getBuilderByPath (
80- url,
81- )? .routeState.copyWith (queryParameters: url.queryParameters);
78+ return _getBuilderByPath (url)? .routeState.copyWith (queryParameters: url.queryParameters);
8279 }
8380
8481 //
@@ -121,9 +118,7 @@ class RouteController {
121118
122119 void clearCache () {
123120 for (final builder in builders) {
124- _widgetCache[builder.routeState] = SizedBox .shrink (
125- key: builder.routeState.key,
126- );
121+ _widgetCache[builder.routeState] = SizedBox .shrink (key: builder.routeState.key);
127122 }
128123 }
129124
@@ -174,10 +169,7 @@ class RouteController {
174169 //
175170 //
176171
177- void pushBack ({
178- RouteState ? fallback,
179- AnimationEffect ? animationEffect = const NoEffect (),
180- }) {
172+ void pushBack ({RouteState ? fallback, AnimationEffect ? animationEffect = const NoEffect ()}) {
181173 if (_prevRouteState.path == '/' ) {
182174 push (fallback ?? fallbackRouteState (), animationEffect: animationEffect);
183175 } else {
@@ -212,22 +204,22 @@ class RouteController {
212204 RouteState ? fallback,
213205 AnimationEffect ? animationEffect,
214206 }) {
215- nextEffect = animationEffect ?? routeState.animationEffect;
207+ _nextEffect = animationEffect ?? routeState.animationEffect;
216208 final uri = routeState.uri;
217209 final skipCurrent = routeState.skipCurrent;
218210 if (skipCurrent && _pRouteState.value.uri == uri) {
219211 return ;
220212 }
221213 if (_checkExtraTypeMismatch <TExtra >(uri) == false ) {
222- debugPrint ( '[RouteController.push] Error !' );
214+ Log . err ( 'Expected extra type $ TExtra for route: $ uri !' );
223215 final errorFallback1 = errorFallback ?? errorRouteState? .call ();
224216 if (errorFallback1 != null ) {
225217 push (errorFallback1);
226218 }
227219 return ;
228220 }
229221 if (! pathExists (uri)) {
230- debugPrint ( '[RouteController.push] Error !' );
222+ Log . err ( 'The path $ uri does not exist !' );
231223 final errorFallback1 = errorFallback ?? errorRouteState? .call ();
232224 if (errorFallback1 != null ) {
233225 push (errorFallback1);
@@ -237,26 +229,22 @@ class RouteController {
237229 final condition = routeState.condition;
238230 final a = condition == null || condition ();
239231 if (! a) {
240- debugPrint ( '[RouteController.push] Condition not met!' );
232+ Log . err ( 'Route condition not met for $ uri !' );
241233 push (fallback ?? fallbackRouteState ());
242234 return ;
243235 }
244236 final condition2 = _getBuilderByPath (uri)? .condition;
245237 final b = condition2 == null || condition2.call ();
246238 if (! b) {
247- debugPrint ( '[RouteController.push] Condition not met!' );
239+ Log . err ( 'Builder condition not met for $ uri !' );
248240 push (fallback ?? fallbackRouteState ());
249241 return ;
250242 }
251243 platformNavigator.pushState (uri);
252-
253244 _prevRouteState = _pRouteState.value;
254-
255- // Remove the previous route state from the cache if it is stale.
256-
257- _pRouteState.value = routeState;
245+ _pRouteState.set (routeState, notifyImmediately: true );
258246 addToCache ([routeState]);
259- _globalKey.currentState? .setEffects ([nextEffect ]);
247+ _globalKey.currentState? .setEffects ([_nextEffect ]);
260248 _globalKey.currentState? .restart ();
261249 }
262250
@@ -283,9 +271,7 @@ class RouteController {
283271 //
284272
285273 RouteBuilder ? _getBuilderByPath (Uri path) {
286- return builders
287- .where ((routeState) => routeState.routeState.path == path.path)
288- .firstOrNull;
274+ return builders.where ((routeState) => routeState.routeState.path == path.path).firstOrNull;
289275 }
290276
291277 //
@@ -329,8 +315,7 @@ class RouteController {
329315 //
330316
331317 static RouteController of (BuildContext context) {
332- final provider = context
333- .dependOnInheritedWidgetOfExactType <RouteControllerProvider >();
318+ final provider = context.dependOnInheritedWidgetOfExactType <RouteControllerProvider >();
334319 if (provider == null ) {
335320 throw FlutterError ('No RouteStateControllerProvider found in context' );
336321 }
0 commit comments