-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
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_routerThe go_router packageThe go_router packagep: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Use case
Right now, the generation creates an extension on each pages:
// routes.dart
@TypedGoRoute< MyRoute1 >(path: '/my-route-1')
class MyRoute1 extends GoRouteData {
const MyRoute1();
@override
Widget build(BuildContext context) => const MyScreen2();
}
@TypedGoRoute< MyRoute2 >(path: '/my-route-1')
class MyRoute2 extends GoRouteData {
const MyRoute2();
@override
Widget build(BuildContext context) => const MyScreen2();
}// routes.g.dart
extension $MyRoute1Extension on MyRoute1 {
static MyRoute1 _fromState(GoRouterState state) => const MyRoute1();
String get location => GoRouteData.$location(
'/my-route-1',
);
void go(BuildContext context) => context.go(location, extra: this);
void push(BuildContext context) => context.push(location, extra: this);
}
extension $MyRoute2Extension on MyRoute2 {
static MyRoute2 _fromState(GoRouterState state) => const MyRoute2();
String get location => GoRouteData.$location(
'/my-route-2',
);
void go(BuildContext context) => context.go(location, extra: this);
void push(BuildContext context) => context.push(location, extra: this);
}But because of that, when manipulating a GoRouteData object, we cannot use go, push or location.
GoRouteData route;
route.go(context); // <- ErrorThis also prevents us from creating an extension on GoRouteData that reuses those methods:
extension on GoRouteData {
void customGo(BuildContext context) {
go(context); // <- Not possible
}
}Proposal
It would be nice if the generated code doesn't work with extension (like what freezed does) for example
abstract class GoRouteMethods {
void go(BuildContext context);
}
class MyRoute extends GoRouteData with _$MyRoute implements GoRouteMethods {}ry-itto, ahmednfwela, om-ha, Ayman-Barghout, mzdm and 13 more
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_routerThe go_router packageThe go_router packagep: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team