- Declare a route that takes a enum with
@QueryParam() tagged.
- The generate
PageRouteInfo provides the query param from the URI as is which is a String and the args expect enum and this will break the flow.
Actual Result
- Maybe In this case I am expected to parse the enum by checking the URI in
deeplinkTransformer but that makes it hard to manage deeplinks with auto route.
Expected Result
- I suggest the builder should be able to parse the enum using it's name. And now it is the responsibility of the developer (me) that I use the same name as the value of the query parameter
- If this is not possible then at least I should be able to define a custom converter in the
@QueryParam object. This would be a callback with the queryParameters map as parameter.
go_router_builder is able to do this same thing.
Code to reproduce
- Example deeplink:
https://www.sample.com/cart?type=rm
- Route declaration
@RoutePage()
class MfUserCartView extends ConsumerStatefulWidget {
const MfUserCartView({
super.key,
@QueryParam('type') required this.userCartType,
});
final MfUserCartTypes? userCartType;
@override
ConsumerState<MfUserCartView> createState() => _MfUserCartViewState();
}
- Generated RouteInfo
/// generated route for
/// [_i79.MfUserCartView]
class MfUserCartRoute extends _i132.PageRouteInfo<MfUserCartRouteArgs> {
MfUserCartRoute({
_i133.Key? key,
required _i148.MfUserCartTypes? userCartType,
List<_i132.PageRouteInfo>? children,
}) : super(
MfUserCartRoute.name,
args: MfUserCartRouteArgs(
key: key,
userCartType: userCartType,
),
rawQueryParams: {'type': userCartType},
initialChildren: children,
);
static const String name = 'MfUserCartRoute';
static _i132.PageInfo page = _i132.PageInfo(
name,
builder: (data) {
final queryParams = data.queryParams;
final args = data.argsAs<MfUserCartRouteArgs>(
orElse: () =>
MfUserCartRouteArgs(userCartType: queryParams.get('type'))); // problem is here.
return _i79.MfUserCartView(
key: args.key,
userCartType: args.userCartType,
);
},
);
}
class MfUserCartRouteArgs {
const MfUserCartRouteArgs({
this.key,
required this.userCartType,
});
final _i133.Key? key;
final _i148.MfUserCartTypes? userCartType;
@override
String toString() {
return 'MfUserCartRouteArgs{key: $key, userCartType: $userCartType}';
}
}
@QueryParam()tagged.PageRouteInfoprovides the query param from the URI as is which is aStringand the args expect enum and this will break the flow.Actual Result
deeplinkTransformerbut that makes it hard to manage deeplinks with auto route.Expected Result
@QueryParamobject. This would be a callback with thequeryParametersmap as parameter.go_router_builderis able to do this same thing.Code to reproduce
https://www.sample.com/cart?type=rm