SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
87 stars 22 forks source link

[Feature Request] add Meta or map key value to add data into #107

Closed AdnaneX closed 1 year ago

AdnaneX commented 1 year ago

Example:

QRoute(
     path: welcome.path,
     name: welcome.name,
     builder: welcome.builder,
     meta: <String, dynamic>{
        "title": "Welcome Page",
     }
 ),
SchabanBo commented 1 year ago

That would be very useful. Do you have an idea how or where to get this map later?

electraport commented 1 year ago

SchabanBo, I have done a few refactors on a project I've been working on for ~9 months based on this router. Coming from Angular, I love what you have done here. The title above is a key element of the meta related to a route. There is some depth here, too, which is that the title will likely be localized and not just a plain string but the result of the intl package. In this case, it needs a BuildContext, and quickly becomes a circular and/or late loading variable problem.

I have been able to solve for much of this but it becomes way more complex than just getting a string property into that metadata. It could also include an array of form fields for the form that renders off that route; each with their own set of internationalized prompts and error messages. The route itself could be built as a factor of abstracting the CRUD methods from objects in use within the application. In that case, I've attached the widget that renders each method as a member of AdnaneX' proposed map.

The map can be collected from a service at runtime based on the name of the active route, etc. and in my case I have used GetX observables. Some detail can be provided by a Controller on the route, too. All of these methods are implemented without needing to extend the router.

I'll give a hint by saying one of the eye-opening intermediate steps was to enumerate the list of unique route names I had within the application, and start running extensions off the enums.

SchabanBo commented 1 year ago

So that now available in V1.8.1 Get it with

QR.currentRoute.meta
// or
QR.navigator.currentRoute.meta