Skip to content
Merged
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
17 changes: 13 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,22 @@ 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.
///
/// When [hasOverriddenOnExit] is null, treat it the same as true for backward compatibility.
_GoRouteParameters _createGoRouteParameters<T extends _GoRouteDataBase>({
required T Function(GoRouterState) factory,
required Expando<_GoRouteDataBase> expando,
bool? hasOverriddenOnExit,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe add a comment about that when hasOverriddenOnExit is null it's handled the same as true for backward compatibility?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hannah-hyj I've added. Please help me review.

}) {
Comment thread
hantrungkien marked this conversation as resolved.
T factoryImpl(GoRouterState state) {
final Object? extra = state.extra;
Expand All @@ -123,8 +126,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 +161,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 +234,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
Contributor 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
Contributor 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chunhtai Hi, is there anything else needed from your side for this PR?

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 of line 3, this is better for source control