Skip to content
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

Inherited params not working and wrong navigation #1827

Open
tomasweigenast opened this issue Jan 2, 2024 · 1 comment
Open

Inherited params not working and wrong navigation #1827

tomasweigenast opened this issue Jan 2, 2024 · 1 comment

Comments

@tomasweigenast
Copy link

tomasweigenast commented Jan 2, 2024

I have the following route hierarchy:

AdaptiveRoute(page: OrdersRouteWrapper.page, path: 'orders', children: [
            AdaptiveRoute(page: OrdersRoute.page, path: '', initial: true),
            AdaptiveRoute(
                page: OrderRoute.page,
                path: ':orderId',
                children: [AdaptiveRoute(page: OrderPaymentProofRoute.page, path: "payment-proof")]),
          ])

(it is not the root, there are other routes above /orders, and I skip them for simplicity).

First of all, I want to mention that I want to navigate to OrderPaymentProofRoute from OrdersRoute, but it will send me to OrderRoute instead of OrderPaymentProofRoute.

But I navigate first to OrderRoute, and then context.navigateTo(OrderPaymentProofRoute()); it throws the following exception:

Error [Failed to parse [String] orderId value from null]
I/flutter (12453): #0      Parameters.getString (package:auto_route/src/common/parameters.dart:61:7)
I/flutter (12453): #1      new _$AppRouter.<anonymous closure>.<anonymous closure> (package:cercanni_customers/ui/router.gr.dart:140:50)
I/flutter (12453): #2      RouteData.argsAs (package:auto_route/src/route/route_data.dart:101:22)
I/flutter (12453): #3      new _$AppRouter.<anonymous closure> (package:cercanni_customers/ui/router.gr.dart:138:30)
I/flutter (12453): #4      RootStackRouter._pageBuilder (package:auto_route/src/router/controller/root_stack_router.dart:169:20)
I/flutter (12453): #5      StackRouter._addEntry (package:auto_route/src/router/controller/routing_controller.dart:1547:29)
I/flutter (12453): #6      StackRouter._pushAllGuarded (package:auto_route/src/router/controller/routing_controller.dart:1522:29)
I/flutter (12453): <asynchronous suspension>
I/flutter (12453): 

router.gr.dart

OrderRoute.name: (routeData) {
      final pathParams = routeData.inheritedPathParams;
      final args = routeData.argsAs<OrderRouteArgs>(
          orElse: () =>
              OrderRouteArgs(orderId: pathParams.getString('orderId'))); // line 140
      return AutoRoutePage<dynamic>(
        routeData: routeData,
        child: OrderView(
          orderId: args.orderId,
          key: args.key,
        ),
      );
    },

OrderPaymentProofView:

@RoutePage()
class OrderPaymentProofView extends StatelessWidget {
  final String orderId;

  const OrderPaymentProofView({@PathParam.inherit() required this.orderId, super.key});
}

OrderView:

@RoutePage()
class OrderView extends HookWidget {
  final String orderId;

  const OrderView({@pathParam required this.orderId, super.key});
}
class OrderPaymentProofRoute extends PageRouteInfo<OrderPaymentProofRouteArgs> {
  OrderPaymentProofRoute({
    Key? key,
    List<PageRouteInfo>? children,
  }) : super(
          OrderPaymentProofRoute.name,
          args: OrderPaymentProofRouteArgs(key: key),
          initialChildren: children,
        );

  static const String name = 'OrderPaymentProofRoute';

  static const PageInfo<OrderPaymentProofRouteArgs> page =
      PageInfo<OrderPaymentProofRouteArgs>(name);
}

class OrderPaymentProofRouteArgs {
  const OrderPaymentProofRouteArgs({this.key});

  final Key? key;

  @override
  String toString() {
    return 'OrderPaymentProofRouteArgs{key: $key}';
  }
}

/// generated route for
/// [OrderView]
class OrderRoute extends PageRouteInfo<OrderRouteArgs> {
  OrderRoute({
    required String orderId,
    Key? key,
    List<PageRouteInfo>? children,
  }) : super(
          OrderRoute.name,
          args: OrderRouteArgs(
            orderId: orderId,
            key: key,
          ),
          rawPathParams: {'orderId': orderId},
          initialChildren: children,
        );

  static const String name = 'OrderRoute';

  static const PageInfo<OrderRouteArgs> page = PageInfo<OrderRouteArgs>(name);
}

class OrderRouteArgs {
  const OrderRouteArgs({
    required this.orderId,
    this.key,
  });

  final String orderId;

  final Key? key;

  @override
  String toString() {
    return 'OrderRouteArgs{orderId: $orderId, key: $key}';
  }
}

Obviously when I navigate to OrderRoute I pass the orderId parameter.

Versions:

auto_route: ^7.8.0
auto_route_generator: ^7.3.1
@tomasweigenast
Copy link
Author

Is this project abandoned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant