-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
customRouteBuilder's completion result type has broken in the 8.0.3 version #1913
Comments
@SergeShkurko try specifiying the type when returning your custom Route e.g |
I have same issue. |
@Milad-Akarie I'm running into the same problem mainly because I have a custom class that extends the I have different class MyRoute extends CustomRoute {
MyRoute({
required super.page,
...
super.opaque,
}) : super(customRouteBuilder: <T>(BuildContext context,
Widget child,
AutoRoutePage<T> page,
) => MyRoutePage<T>(
builder: (context) => child,
settings: page,
));
} I solved with this workaround that forces me to specify the return type in the navigation tree declaration too: class MyRoute<R> extends CustomRoute {
MyRoute({
required super.page,
...
super.opaque,
}) : super(customRouteBuilder: (BuildContext context,
Widget child,
AutoRoutePage<T> page,
) => MyRoutePage<R>(
builder: (context) => child,
settings: page,
));
} |
We encounter the same issue for 8.0.3.
|
Any plans on fixing this issue? |
Still same issues for me when I upgrade auto_route to Ver. 8, with my both custom bottomSheet route and dialog route. |
Any updates on this issue? |
Make sure your return type is exclusively provided in both annotation and route implementation. @RoutePage<String>() /// this page returns a string value
class MyPage extends StatelessWidget {} CustomRoute(
page: MyRoute.page,
customRouteBuilder: (context, child, page) {
return MyCustomRoute<String>( // provide the same return type
builder: (context) => child,
settings: page,
);
},
), |
My custom route screen is @RoutePage<bool>(name: 'ProductInfoBottomSheetRoute')
class ProductInfoBottomSheet extends ConsumerWidget {
const ProductInfoBottomSheet({
super.key,
@pathParam required this.productId,
});
final String productId; my route is AppCustomBottomSheetRoute<bool>(
path: 'warehouse/myorder/detail/:productId',
page: ProductInfoBottomSheetRoute.page,
), and my class AppCustomBottomSheetRoute<T> extends CustomRoute {
AppCustomBottomSheetRoute({
required String super.path,
required super.page,
super.barrierDismissible = false,
Color? barrierColor,
bool isScrollControlled = true,
super.children,
}) : super(
opaque: false,
barrierColor: barrierColor ?? Colors.black.withOpacity(0.48),
fullscreenDialog: false,
transitionsBuilder: TransitionsBuilders.noTransition,
customRouteBuilder: <T>(BuildContext context, Widget child, AutoRoutePage<T> page) {
return ModalBottomSheetRoute<T>(
settings: page,
builder: (context) => child,
isScrollControlled: isScrollControlled,
);
},
);
} when I try to push like await context.router.pushNamed<bool>('warehouse/myorder/detail/${item.id}').then((bool? value) {
if (value ?? false) {
Future.delayed(const Duration(milliseconds: 150), () {
context.router.pushNamed('warehouse/edit-product/${item.id}');
});
}
}); Note: this implementation work fine before upgrade to auto_route 8, after that upgrade, it throw me an error and I cannot work with custom route anymore |
Did you run the generator after setting @RoutePage |
@Milad-Akarie Yes, my ProductInfoBottomSheetRoute.name: (routeData) {
final pathParams = routeData.inheritedPathParams;
final args = routeData.argsAs<ProductInfoBottomSheetRouteArgs>(
orElse: () => ProductInfoBottomSheetRouteArgs(
productId: pathParams.getString('productId')));
return AutoRoutePage<bool>(
routeData: routeData,
child: ProductInfoBottomSheet(
key: args.key,
productId: args.productId,
),
);
},
/// generated route for
/// [ProductInfoBottomSheet]
class ProductInfoBottomSheetRoute
extends PageRouteInfo<ProductInfoBottomSheetRouteArgs> {
ProductInfoBottomSheetRoute({
Key? key,
required String productId,
List<PageRouteInfo>? children,
}) : super(
ProductInfoBottomSheetRoute.name,
args: ProductInfoBottomSheetRouteArgs(
key: key,
productId: productId,
),
rawPathParams: {'productId': productId},
initialChildren: children,
);
static const String name = 'ProductInfoBottomSheetRoute';
static const PageInfo<ProductInfoBottomSheetRouteArgs> page =
PageInfo<ProductInfoBottomSheetRouteArgs>(name);
}
class ProductInfoBottomSheetRouteArgs {
const ProductInfoBottomSheetRouteArgs({
this.key,
required this.productId,
});
final Key? key;
final String productId;
@override
String toString() {
return 'ProductInfoBottomSheetRouteArgs{key: $key, productId: $productId}';
}
} with you can see #1942 is a fix of this custom route error that now I using it instead of official in pub version, you should review it. |
Same thing here. I'm specifying a custom route type via type in routes:
The error is:
Which is quite logical, since |
Did it was resolved in latest 9.3.0? |
Now, return types don't work with customRouteBuilder correctly
Because of the last commit c2953fe. Type annotation removed from the function
Then any reusable
customRouteBuilder
implementation will return Route with a dynamic type. We won't return any route with passed by router type. We need to handle generics inside the function. Like earlierMore earlier versions work pretty
The text was updated successfully, but these errors were encountered: