Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

[Proposal] Change navigatorBuilder signature to (BuildContext, Widget, GoRouterState) #171

Closed
esDotDev opened this issue Nov 18, 2021 · 1 comment
Labels
breaking change enhancement New feature or request

Comments

@esDotDev
Copy link

esDotDev commented Nov 18, 2021

This would fix a couple of problems with the existing signature:

  1. The Widget? misleads the reader into thinking child may be null, when it never will, and forces the writer to add a redundant ! operator.

  2. It's awkward to make decisions inside of navigatorBuilder without a reference to the router or state, because you can not access the goRouter instance when defining it.

class _MyAppState extends State<MyApp> {

  GoRouter goRouter = GoRouter(
    navigatorBuilder: (_, child) {
      if (goRouter.location == '/') return child!; // ERROR: error: The instance member 'goRouter' can't be accessed in an initializer. 
      return MainScaffold(child: child!);
    },

I can access the router if I define it as a package level variable, but not when it is inside of a class or method.

[Edit] Actually it will work as a class field, if declared as late, which is great. Still no go inside of method though, like initState

@csells csells added enhancement New feature or request breaking change labels Nov 20, 2021
@csells csells mentioned this issue Nov 21, 2021
9 tasks
@csells
Copy link
Owner

csells commented Jan 5, 2022

fixed in v3.0.0

@csells csells closed this as completed Jan 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants