@@ -62,7 +62,7 @@ typedef GoExceptionHandler = void Function(
6262/// {@category Deep linking}
6363/// {@category Error handling}
6464/// {@category Named routes}
65- class GoRouter extends ChangeNotifier implements RouterConfig <RouteMatchList > {
65+ class GoRouter implements RouterConfig <RouteMatchList > {
6666 /// Default constructor to configure a GoRouter with a routes builder
6767 /// and an error page builder.
6868 ///
@@ -152,7 +152,6 @@ class GoRouter extends ChangeNotifier implements RouterConfig<RouteMatchList> {
152152 builderWithNav: (BuildContext context, Widget child) =>
153153 InheritedGoRouter (goRouter: this , child: child),
154154 );
155- routerDelegate.addListener (_handleStateMayChange);
156155
157156 assert (() {
158157 log.info ('setting initial location $initialLocation ' );
@@ -296,34 +295,9 @@ class GoRouter extends ChangeNotifier implements RouterConfig<RouteMatchList> {
296295 @override
297296 late final GoRouteInformationParser routeInformationParser;
298297
299- /// Gets the current location.
300- // TODO(chunhtai): deprecates this once go_router_builder is migrated to
301- // GoRouterState.of.
302- String get location => _location;
303- String _location = '/' ;
304-
305298 /// Returns `true` if there is at least two or more route can be pop.
306299 bool canPop () => routerDelegate.canPop ();
307300
308- void _handleStateMayChange () {
309- final String newLocation;
310- if (routerDelegate.currentConfiguration.isNotEmpty &&
311- routerDelegate.currentConfiguration.matches.last
312- is ImperativeRouteMatch ) {
313- newLocation = (routerDelegate.currentConfiguration.matches.last
314- as ImperativeRouteMatch )
315- .matches
316- .uri
317- .toString ();
318- } else {
319- newLocation = routerDelegate.currentConfiguration.uri.toString ();
320- }
321- if (_location != newLocation) {
322- _location = newLocation;
323- notifyListeners ();
324- }
325- }
326-
327301 /// Get a location from route name and parameters.
328302 /// This is useful for redirecting to a named location.
329303 String namedLocation (
@@ -488,7 +462,7 @@ class GoRouter extends ChangeNotifier implements RouterConfig<RouteMatchList> {
488462 /// of any GoRoute under it.
489463 void pop <T extends Object ?>([T ? result]) {
490464 assert (() {
491- log.info ('popping $location ' );
465+ log.info ('popping ${ routerDelegate . currentConfiguration . uri } ' );
492466 return true ;
493467 }());
494468 routerDelegate.pop <T >(result);
@@ -497,7 +471,7 @@ class GoRouter extends ChangeNotifier implements RouterConfig<RouteMatchList> {
497471 /// Refresh the route.
498472 void refresh () {
499473 assert (() {
500- log.info ('refreshing $location ' );
474+ log.info ('refreshing ${ routerDelegate . currentConfiguration . uri } ' );
501475 return true ;
502476 }());
503477 routeInformationProvider.notifyListeners ();
@@ -507,8 +481,7 @@ class GoRouter extends ChangeNotifier implements RouterConfig<RouteMatchList> {
507481 ///
508482 /// This method throws when it is called during redirects.
509483 static GoRouter of (BuildContext context) {
510- final InheritedGoRouter ? inherited =
511- context.dependOnInheritedWidgetOfExactType <InheritedGoRouter >();
484+ final InheritedGoRouter ? inherited = maybeOf (context);
512485 assert (inherited != null , 'No GoRouter found in context' );
513486 return inherited! .goRouter;
514487 }
@@ -517,17 +490,16 @@ class GoRouter extends ChangeNotifier implements RouterConfig<RouteMatchList> {
517490 ///
518491 /// This method returns null when it is called during redirects.
519492 static GoRouter ? maybeOf (BuildContext context) {
520- final InheritedGoRouter ? inherited =
521- context.dependOnInheritedWidgetOfExactType <InheritedGoRouter >();
493+ final InheritedGoRouter ? inherited = context
494+ .getElementForInheritedWidgetOfExactType <InheritedGoRouter >()
495+ ? .widget as InheritedGoRouter ? ;
522496 return inherited? .goRouter;
523497 }
524498
525- @override
499+ /// Disposes resource created by this object.
526500 void dispose () {
527501 routeInformationProvider.dispose ();
528- routerDelegate.removeListener (_handleStateMayChange);
529502 routerDelegate.dispose ();
530- super .dispose ();
531503 }
532504
533505 String _effectiveInitialLocation (String ? initialLocation) {
0 commit comments