Skip to content

[go_router_builder]: In version 2.8.1 or later, using a required value for queryParameters will result in a build error #164358

Closed as duplicate of#164354
@Karibash

Description

@Karibash

Steps to reproduce

Define a route with required values as follows.

import 'package:go_router/go_router.dart';

@TypedGoRoute<NonNullableRequiredParamNotInPath>(path: 'bob')
class NonNullableRequiredParamNotInPath extends GoRouteData {
  NonNullableRequiredParamNotInPath({required this.id});
  final int id;
}

Expected results

The build should be able to execute normally.

Actual results

A nullable error occurs when building.

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'app.g.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  App({super.key});

  @override
  Widget build(BuildContext context) => MaterialApp.router(
        routerConfig: _router,
        title: 'GoRouter Example',
      );

  final GoRouter _router = GoRouter(routes: $appRoutes);
}

@TypedGoRoute< HomeRoute >(path: '/')
class HomeRoute extends GoRouteData {
  HomeRoute({required this.id});
  final int id;

  @override
  Widget build(BuildContext context, GoRouterState state) {
    return HomeScreen(id: id);
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key, required this.id});
  final int id;

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: const Text('GoRouter Example')),
        body: Text(id.toString()),
      );
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3 24D60 darwin-arm64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.3.2.2)
[✓] VS Code (version 1.96.4)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions