This is kind of an extension to #108437
Use case
I'm using go router builder and I have a route with optional parameters:
enumMyEnum {
myFirstEntry,
mySecondEntry,
}
@TypedGoRoute<MyRoute>(path:'/my-path')
classMyRouteextendsGoRouteData {
constMyRoute({
this.myBoolean =false,
this.myEnum,
});
finalbool myBoolean;
finalMyEnum? myEnum;
@overrideWidgetbuild(BuildContext context) =>constMyScreen();
}If I want myBoolean to be true, it forces the url to be my-boolean=true. But I might want another formatting, like myBoolean=true (parameter not in kebab-case) or my-boolean=t (t instead of true).
There is the same issue with myEnum, it forces the url parameter to be my-enum (but I could want to keep myEnum) and the values to be kebab-case like my-first-route (but I could want to keep myFirstEntry : myEnum=myFirstEntry).
In my case, those parameters are set by a thrid party of my app and I cannot control them or change them, which prevents me from using go_router_builder.
Proposal
It could be nice to allow us to specify the formatting/create a converter like json_serializable and JsonConverter.
enumMyEnum {
myFirstEntry,
mySecondEntry,
}
@TypedGoRoute<MyRoute>(path:'/my-path')
classMyRouteextendsGoRouteData {
constMyRoute({
this.myBoolean =false,
this.myEnum,
});
@TypedGoRouteParameter<bool>(name:'my-boolean')
finalbool myBoolean;
@MyEnumConverter()
finalMyEnum? myEnum;
@overrideWidgetbuild(BuildContext context) =>constMyScreen();
}
classMyEnumConverterextendsTypedGoRouteParameter<MyEnum> {
classMyEnumConverter(super.name);
@overrideString?toUrlString(MyEnum myEnum) {
// Return the correct format here.// If `null` is returned, fall back to the existing behavior.
}
@overrideMyEnum?fromUrlString(String value) {
// Return the correct value here.// If `null` is returned, fall back to the existing behavior.
}
}
This is kind of an extension to #108437
Use case
I'm using go router builder and I have a route with optional parameters:
If I want
myBooleanto be true, it forces theurlto bemy-boolean=true. But I might want another formatting, likemyBoolean=true(parameter not inkebab-case) ormy-boolean=t(tinstead oftrue).There is the same issue with
myEnum, it forces the url parameter to bemy-enum(but I could want to keepmyEnum) and the values to bekebab-caselikemy-first-route(but I could want to keepmyFirstEntry:myEnum=myFirstEntry).In my case, those parameters are set by a thrid party of my app and I cannot control them or change them, which prevents me from using go_router_builder.
Proposal
It could be nice to allow us to specify the formatting/create a converter like
json_serializableandJsonConverter.