-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Allow users to specify onExit as optional #11150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -90,19 +90,20 @@ class _GoRouteParameters { | |||||||||||||||||||||||||||||||||||||||||||||
| required this.builder, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.pageBuilder, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.redirect, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.onExit, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.onExit, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| final GoRouterWidgetBuilder builder; | ||||||||||||||||||||||||||||||||||||||||||||||
| final GoRouterPageBuilder pageBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||
| final GoRouterRedirect redirect; | ||||||||||||||||||||||||||||||||||||||||||||||
| final ExitCallback onExit; | ||||||||||||||||||||||||||||||||||||||||||||||
| final ExitCallback? onExit; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Helper to create [GoRoute] parameters from a factory function and an Expando. | ||||||||||||||||||||||||||||||||||||||||||||||
| _GoRouteParameters _createGoRouteParameters<T extends _GoRouteDataBase>({ | ||||||||||||||||||||||||||||||||||||||||||||||
| required T Function(GoRouterState) factory, | ||||||||||||||||||||||||||||||||||||||||||||||
| required Expando<_GoRouteDataBase> expando, | ||||||||||||||||||||||||||||||||||||||||||||||
| bool overrideOnExit = false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||
| T factoryImpl(GoRouterState state) { | ||||||||||||||||||||||||||||||||||||||||||||||
| final Object? extra = state.extra; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -123,8 +124,10 @@ _GoRouteParameters _createGoRouteParameters<T extends _GoRouteDataBase>({ | |||||||||||||||||||||||||||||||||||||||||||||
| factoryImpl(state).buildPage(context, state), | ||||||||||||||||||||||||||||||||||||||||||||||
| redirect: (BuildContext context, GoRouterState state) => | ||||||||||||||||||||||||||||||||||||||||||||||
| factoryImpl(state).redirect(context, state), | ||||||||||||||||||||||||||||||||||||||||||||||
| onExit: (BuildContext context, GoRouterState state) => | ||||||||||||||||||||||||||||||||||||||||||||||
| factoryImpl(state).onExit(context, state), | ||||||||||||||||||||||||||||||||||||||||||||||
| onExit: overrideOnExit | ||||||||||||||||||||||||||||||||||||||||||||||
| ? (BuildContext context, GoRouterState state) => | ||||||||||||||||||||||||||||||||||||||||||||||
| factoryImpl(state).onExit(context, state) | ||||||||||||||||||||||||||||||||||||||||||||||
| : null, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -156,10 +159,12 @@ abstract class GoRouteData extends _GoRouteDataBase { | |||||||||||||||||||||||||||||||||||||||||||||
| required T Function(GoRouterState) factory, | ||||||||||||||||||||||||||||||||||||||||||||||
| GlobalKey<NavigatorState>? parentNavigatorKey, | ||||||||||||||||||||||||||||||||||||||||||||||
| List<RouteBase> routes = const <RouteBase>[], | ||||||||||||||||||||||||||||||||||||||||||||||
| bool overrideOnExit = false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||
| final _GoRouteParameters params = _createGoRouteParameters<T>( | ||||||||||||||||||||||||||||||||||||||||||||||
| factory: factory, | ||||||||||||||||||||||||||||||||||||||||||||||
| expando: _GoRouteDataBase.stateObjectExpando, | ||||||||||||||||||||||||||||||||||||||||||||||
| overrideOnExit: overrideOnExit, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return GoRoute( | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -227,10 +232,12 @@ abstract class RelativeGoRouteData extends _GoRouteDataBase { | |||||||||||||||||||||||||||||||||||||||||||||
| required T Function(GoRouterState) factory, | ||||||||||||||||||||||||||||||||||||||||||||||
| GlobalKey<NavigatorState>? parentNavigatorKey, | ||||||||||||||||||||||||||||||||||||||||||||||
| List<RouteBase> routes = const <RouteBase>[], | ||||||||||||||||||||||||||||||||||||||||||||||
| bool overrideOnExit = false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||
| final _GoRouteParameters params = _createGoRouteParameters<T>( | ||||||||||||||||||||||||||||||||||||||||||||||
| factory: factory, | ||||||||||||||||||||||||||||||||||||||||||||||
| expando: _GoRouteDataBase.stateObjectExpando, | ||||||||||||||||||||||||||||||||||||||||||||||
| overrideOnExit: overrideOnExit, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return GoRoute( | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -483,6 +490,7 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> { | |||||||||||||||||||||||||||||||||||||||||||||
| this.name, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.routes = const <TypedRoute<RouteData>>[], | ||||||||||||||||||||||||||||||||||||||||||||||
| this.caseSensitive = true, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.overrideOnExit = false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// The path that corresponds to this route. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -515,6 +523,18 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> { | |||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Defaults to `true`. | ||||||||||||||||||||||||||||||||||||||||||||||
| final bool caseSensitive; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Whether to override the default behavior of [GoRoute.onExit] to invoke the | ||||||||||||||||||||||||||||||||||||||||||||||
| /// [GoRouteData.onExit] method of the route data class. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// When `true`, the [GoRouteData.onExit] method will be invoked when | ||||||||||||||||||||||||||||||||||||||||||||||
| /// the route is removed from GoRouter's route history. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// When `false`, the default behavior is used, which does not invoke | ||||||||||||||||||||||||||||||||||||||||||||||
| /// the [GoRouteData.onExit] method. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Defaults to `false`. | ||||||||||||||||||||||||||||||||||||||||||||||
| final bool overrideOnExit; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+527
to
+537
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name Also, the documentation says 'Whether to override the default behavior of Perhaps the documentation could be rephrased for clarity. This comment also applies to
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// A superclass for each typed relative go route descendant | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -526,6 +546,7 @@ class TypedRelativeGoRoute<T extends RelativeGoRouteData> | |||||||||||||||||||||||||||||||||||||||||||||
| required this.path, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.routes = const <TypedRoute<RouteData>>[], | ||||||||||||||||||||||||||||||||||||||||||||||
| this.caseSensitive = true, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.overrideOnExit = false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// The relative path that corresponds to this route. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -550,6 +571,18 @@ class TypedRelativeGoRoute<T extends RelativeGoRouteData> | |||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Defaults to `true`. | ||||||||||||||||||||||||||||||||||||||||||||||
| final bool caseSensitive; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Whether to override the default behavior of [GoRoute.onExit] to invoke the | ||||||||||||||||||||||||||||||||||||||||||||||
| /// [RelativeGoRouteData.onExit] method of the route data class. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// When `true`, the [RelativeGoRouteData.onExit] method will be invoked when | ||||||||||||||||||||||||||||||||||||||||||||||
| /// the route is removed from GoRouter's route history. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// When `false`, the default behavior is used, which does not invoke | ||||||||||||||||||||||||||||||||||||||||||||||
| /// the [RelativeGoRouteData.onExit] method. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Defaults to `false`. | ||||||||||||||||||||||||||||||||||||||||||||||
| final bool overrideOnExit; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// A superclass for each typed shell route descendant | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name: go_router | ||
| description: A declarative router for Flutter based on Navigation 2 supporting | ||
| deep linking, data-driven routes and more | ||
| version: 17.1.0 | ||
| version: 17.2.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change appears to be a breaking change. Previously, |
||
| repository: https://github.com/flutter/packages/tree/main/packages/go_router | ||
| issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.