1

With a MaterialApp you can provide the navigatorKey and use that in your middleware to redirect the user if necessary (as it's done in the flutter redux example).

But CupertinoApp doesn’t have a navigatorKey.

What we are doing now is to add the context to the action so we have access to it in the middleware, and can then user Navigator.of(context), but this seems very wrong.

What is the best way to achieve this?

enyo
  • 16,269
  • 9
  • 56
  • 73
  • Make a Pull Request – Rémi Rousselet Sep 24 '18 at 13:49
  • @RémiRousselet to the `CupertinoApp` to add `navigatorKey` you mean? – enyo Sep 24 '18 at 14:09
  • Yes exactly. If should be really easy to do – Rémi Rousselet Sep 24 '18 at 14:14
  • Mh Ok. I just didn't know whether this is the proper way to do it, or if there are other trivial solutions to this problem that don't require a PR. But if that will make it easier I'll tackle it. – enyo Sep 24 '18 at 14:18
  • Well you should be able to do without it by using `builder` property though – Rémi Rousselet Sep 24 '18 at 14:22
  • @RémiRousselet would you mind elaborating a bit? – enyo Sep 25 '18 at 11:08
  • By using `builder` you could create your middleware here, so that it is binded to the Navigator – Rémi Rousselet Sep 25 '18 at 11:19
  • Mh ok, but when using the `CupertinoApp` routes, we don't write our code in the `builder`, and the `context` from the parent widget's `builder` can't be used because the `Navigator` is not available there... – enyo Sep 25 '18 at 12:22
  • Navigator is available inside `CupertinoApp`'s builder – Rémi Rousselet Sep 25 '18 at 12:23
  • How? The `builder` function provides `context` and `widget`. How do I get the navigator our of that? `Navigator.of(context)` doesn't work in that context, because this context is not a child of a navigator (or similar). – enyo Sep 25 '18 at 12:45
  • `Navigator.of(context)` does work in that context. It is a child of navigator. It's made exactly for that – Rémi Rousselet Sep 25 '18 at 12:57
  • We have a `CupertinoApp` (with `routes`), and when trying to access the `Navigator` inside the `builder` like this: `Navigator.of(context)` we get: `Navigator operation requested with a context that does not include a Navigator` – enyo Sep 25 '18 at 13:01
  • Indeed sorry. But that's a bug then. As it's possible with MaterialApp. Consider making an issue – Rémi Rousselet Sep 25 '18 at 13:58

1 Answers1

2

navigatorKey has been added to the CupertinoApp.

enyo
  • 16,269
  • 9
  • 56
  • 73