-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Closed
flutter/packages
#4039Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Use case
In some scenario, some routes (ex: /my-route/:route-id
) requires to always have a parameter (ex: /my-route/:route-id?my-param=my-value
)
I would like to enforce the generated code and developers to always specify this parameter:
MyRoute(routeId: 'routeId', myParam: 'myValue').location; // <- OK
MyRoute(routeId: 'routeId').location; // <- KO: `myParam` is required
by doing:
@TypedRoute<MyRoute>(path: '/my-route/:route-id')
class MyRoute extends GoRouteData {
MyRoute({
required this.routeId,
required this.myParam,
});
final String routeId;
final String myParam;
}
Right now, I can only use assert
s:
@TypedRoute<MyRoute>(path: '/my-route/:route-id')
class MyRoute extends GoRouteData {
MyRoute({
required this.routeId,
this.myParam = '',
}): assert(myParam.isNotEmpty);
final String routeId;
final String myParam;
}
but this doesn't give a check at compilation time, it only fails at running time.
Proposal
It would be nice to support required query parameters:
@TypedRoute<MyRoute>(path: '/my-route/:route-id')
class MyRoute extends GoRouteData {
MyRoute({
required this.routeId,
required this.myParam,
});
final String routeId;
final String myParam;
}
dancamdev and Maatteogekko
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.