Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/go_router/lib/src/route_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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? hasOverriddenOnExit,
}) {
T factoryImpl(GoRouterState state) {
final Object? extra = state.extra;
Expand All @@ -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: hasOverriddenOnExit == null || hasOverriddenOnExit
? (BuildContext context, GoRouterState state) =>
factoryImpl(state).onExit(context, state)
: null,
);
}

Expand Down Expand Up @@ -156,10 +159,12 @@ abstract class GoRouteData extends _GoRouteDataBase {
required T Function(GoRouterState) factory,
GlobalKey<NavigatorState>? parentNavigatorKey,
List<RouteBase> routes = const <RouteBase>[],
bool? hasOverriddenOnExit,
}) {
final _GoRouteParameters params = _createGoRouteParameters<T>(
factory: factory,
expando: _GoRouteDataBase.stateObjectExpando,
hasOverriddenOnExit: hasOverriddenOnExit,
);

return GoRoute(
Expand Down Expand Up @@ -227,10 +232,12 @@ abstract class RelativeGoRouteData extends _GoRouteDataBase {
required T Function(GoRouterState) factory,
GlobalKey<NavigatorState>? parentNavigatorKey,
List<RouteBase> routes = const <RouteBase>[],
bool? hasOverriddenOnExit,
}) {
final _GoRouteParameters params = _createGoRouteParameters<T>(
factory: factory,
expando: _GoRouteDataBase.stateObjectExpando,
hasOverriddenOnExit: hasOverriddenOnExit,
);

return GoRoute(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog: |
- Adds `hasOverriddenOnExit` parameter to `GoRouteData.$route` and `RelativeGoRouteData.$route` helper methods for type-safe routes. When set to `true`, enables custom `onExit` callback invocation from route data classes extending `GoRouteData` or `RelativeGoRouteData` when the route is removed from the navigation stack.
version: minor
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a new line at the end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chunhtai Actually, my file only has 3 lines. It seems like the issue happens because the changelog values are long, so it ends up like this—similar to this file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chunhtai I checked again in the browser on an extended screen that is larger than the MacBook’s screen, and everything looks fine.