csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
441 stars 97 forks source link

[Question] Possibility to pass complex arguments to routes #42

Closed raulmabe closed 3 years ago

raulmabe commented 3 years ago

Hi 👋🏼 ! Firstly I'd like to thank you for this package 💙

Problem

I have a use case where I need to pass complex objects as arguments to some pages (instead of an ID). I haven't seen anything related on the docs so I asked myself if this is possible with the current package implementation.

As far as I understand the only way to pass arguments to routes with the package paradigm is via query parameters, which has a limit between 1024 and 2048 characters; which may cause me trouble in the future...

csells commented 3 years ago

go_router doesn't support this on purpose because it can't work in URLs, which means it can't support dynamic linking, deep linking, etc. However, in that case, you can use the old-style Navigator API, which is still available and supported; e.g. this call to Navigator.push in the books sample.

raulmabe commented 3 years ago

I didn't know Navigator.push was still available to use . I assume then that Navigator.pushNamed isn't supported as MaterialApp.router lacks the onGenerateRoute parameter. (I am not very familiar with the MaterialApp.router ctor)

If this is true, would be awesome to support the old-style Navigator with named pages. Maybe through an additional optional parameter inside GoRoute (pageRouteBuilder) which takes a Route instead of a Page, and links the named route to this pageRouteBuilder. So we could call context.pushNamed('register', args: ComplexObject()), but still support for query navigation.

csells commented 3 years ago

You can also implement onGenerateRoute yourself, e.g.

MaterialApp.router(..., onGenerateRoute: myRouteGenerator)

raulmabe commented 3 years ago

Actually, the MaterialApp.router sets the onGenerateRoute property to null without option to implement it myself...

csells commented 3 years ago

well darn it...