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

Generated Route has no key constructor parameter, when it is the only parameter in the corresponding widget/screen #2083

Open
Sevastyan opened this issue Nov 3, 2024 · 0 comments

Comments

@Sevastyan
Copy link

This is my screen:

@RoutePage()
class InitializationInvitationMissingScreen extends StatelessWidget {
  const InitializationInvitationMissingScreen({super.key});

  static const route = InitializationInvitationMissingRoute.new;

  @override
  Widget build(BuildContext context) => ...;
}

and this is what's getting generated:

/// generated route for
/// [_i6.InitializationInvitationMissingScreen]
class InitializationInvitationMissingRoute extends _i16.PageRouteInfo<void> {
  const InitializationInvitationMissingRoute(
      {List<_i16.PageRouteInfo>? children})
      : super(
          InitializationInvitationMissingRoute.name,
          initialChildren: children,
        );

  static const String name = 'InitializationInvitationMissingRoute';

  static const _i16.PageInfo<void> page = _i16.PageInfo<void>(name);
}

Notice that I cannot pass key to the route.

This is my workaround:

@RoutePage()
class InitializationInvitationMissingScreen extends StatelessWidget {
  const InitializationInvitationMissingScreen({super.key, required this.placeholder});

  final String placeholder;

  static const route = InitializationInvitationMissingRoute.new;

  @override
  Widget build(BuildContext context) => WalletScaffold(
        title: context.l10n.appName,
        keycard: const KeycardBlank(),
        children: [
          const SizedBox(height: 48),
          InfoWidget(
            title: context.l10n.invitationMissingTitle,
            body: context.l10n.invitationMissingBody,
          ),
        ],
      );
}

it generates:

// generated route for
/// [_i6.InitializationInvitationMissingScreen]
class InitializationInvitationMissingRoute
    extends _i16.PageRouteInfo<InitializationInvitationMissingRouteArgs> {
  InitializationInvitationMissingRoute({
    _i18.Key? key,
    required String placeholder,
    List<_i16.PageRouteInfo>? children,
  }) : super(
          InitializationInvitationMissingRoute.name,
          args: InitializationInvitationMissingRouteArgs(
            key: key,
            placeholder: placeholder,
          ),
          initialChildren: children,
        );

  static const String name = 'InitializationInvitationMissingRoute';

  static const _i16.PageInfo<InitializationInvitationMissingRouteArgs> page =
      _i16.PageInfo<InitializationInvitationMissingRouteArgs>(name);
}
auto_route: ^7.8.4
auto_route_generator: ^7.3.2
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