Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router_builder] Proposal to improve how we handle extra parameters #117261

Open
dancamdev opened this issue Dec 17, 2022 · 5 comments
Open

[go_router_builder] Proposal to improve how we handle extra parameters #117261

dancamdev opened this issue Dec 17, 2022 · 5 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter p: go_router_builder The go_router_builder package P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team

Comments

@dancamdev
Copy link

In the current version of go_router_builder this is the only way to handle extra parameters to the route.

class PersonRouteWithExtra extends GoRouteData {
  PersonRouteWithExtra({this.$extra});
  final int? $extra;

  @override
  Widget build(BuildContext context) => PersonScreen(personId: $extra);
}

This comes with some major developer experience drawbacks in my opinion, among which, the biggest are:

  • forced named parameter
  • parameter type must be optional because it must be named and cannot be required
  • parameter must be named $extra

This leads to having roughly the following line every time you need to use the route (which btw wrongly shows a positional argument in the documentation):

PersonRouteWithExtra($extra: Person(name: 'Marvin', age: 42)).go(context);

Ideally, I would have a positional parameter or be able to have a custom named one.

The purpose of this issue is to discuss potential improvements on the API

@dancamdev
Copy link
Author

Specifically tackling the

parameter name must be $extra

We could define a decorator that's responsible for making sure the generator knows which parameter is the extra one, instead of relying on the name.

Ideally, something along this line:

class PersonRouteWithExtra extends GoRouteData {
  PersonRouteWithExtra({this.$extra});
  @Extra() final int? id;

  @override
  Widget build(BuildContext context) => PersonScreen(personId: id);
}

Which would result in a much more clean way of using the route.

PersonRouteWithExtra(id: person.id).go(context);

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Dec 19, 2022
@darshankawar
Copy link
Member

@dancamdev
Can you take a look at this issue and see if your use case is same ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 19, 2022
@dancamdev
Copy link
Author

@dancamdev

Can you take a look at this issue and see if your use case is same ?

My proposed solution is exactly the same, yes.

Still, this issue aims to discuss broader fixes to extra - not only the variable name. Passing it as a positional parameter or requiring it if named and non-nullable would be what it really makes it more convenient than go_router.

At the moment I see too many compromises. I tried go_router_builder, I've seen it got in the way of what I was trying to achieve and went back to go_router

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 19, 2022
@darshankawar
Copy link
Member

Thanks for the update. I will keep this issue open and treat it as feature request based on above comment.

@darshankawar darshankawar added c: new feature Nothing broken; request for a new capability p: first party package flutter/packages repository. See also p: labels. c: proposal A detailed proposal for a change to Flutter p: go_router_builder The go_router_builder package and removed in triage Presently being triaged by the triage team labels Dec 19, 2022
@stuartmorgan stuartmorgan added the P3 Issues that are less important to the Flutter project label Jan 10, 2023
@JasCodes
Copy link

Is it possible to use @QyeryParameter() final int studentID; to maker a query paramerter as required?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter p: go_router_builder The go_router_builder package P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team
Projects
No open projects
Status: No status
Development

No branches or pull requests

5 participants