Skip to content

Proposal: [go_router_builder] Allow users to specify onExit as optional #183099

Description

@hantrungkien

Use Case

I'm using go_router_builder and have three routes

HomeRouteData, Details1RouteData, and Details2RouteData, corresponding to HomePage, Details1Page, and Details2Page.

On HomePage, I push Details1Page and wait for a returned result. here
On Details1Page, I push Details2Page and wait for a result. here
On Details2Page, I pop to return to Details1Page. here
At that point, I continue to pop to go back to HomePage from Details1Page, but I can’t. here

After investigating the root cause, I found that the issue is due to the onExit callback always being passed into the GoRoute constructor.

Proposal

Option 1:

Use a variable similar to caseSensitive to determine whether this route implements the onExit callback.

  const TypedGoRoute({
    required this.path,
    this.name,
    this.routes = const <TypedRoute<RouteData>>[],
    this.caseSensitive = true,
    this.overrideOnExit = false,
  });

Option 2:

Check whether the child route actually overrides the onExit function at the time build_runner runs: go_router_builder

        final bool hasOverriddenOnExit = classElement.methods.any(
          (method) => method.name == 'onExit',
        );

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagep: go_router_builderThe go_router_builder packagepackageflutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions