Repository: flutter
Issue: [go_router] [go_router_builder] Exception with typed extra
Labels: c: crash,package,a: error message,has reproducible steps,P2,p: go_router,found in release: 3.10,found in release: 3.11,team-go_router,triaged-go_router

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Generate code with flutter pub run build_runner build (go_router: 7.0.1, go_router_builder: 2.0.0)
2. Run app bellow
3. Tap on button "go 1"
4. Tap on button "go 2"

### Expected results

after point 4(Tap on button "go 2") go to third screen (TwoScreen)

### Actual results

exception and stay on the previous screen

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'main.g.dart';

final _router = GoRouter(routes: $appRoutes);

class ExtraParam {
  final int i;
  final int j;

  const ExtraParam(this.i, this.j);
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.amber,
      child: Center(
        child: OutlinedButton(
          onPressed: () {
            const OneRoute($extra: ExtraParam(1, 1)).push(context);
          },
          child: const Text("go 1"),
        ),
      ),
    );
  }
}

class OneScreen extends StatelessWidget {
  final ExtraParam? extra;

  const OneScreen({super.key, this.extra});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.pinkAccent,
      child: Center(
        child: OutlinedButton(
          onPressed: () {
            TwoRoute().push(context);
          },
          child: Text("go 2"),
        ),
      ),
    );
  }
}

class TwoScreen extends StatelessWidget {
  const TwoScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.green,
      child: Center(
        child: OutlinedButton(
          onPressed: () {},
          child: Text("go 3"),
        ),
      ),
    );
  }
}

@TypedGoRoute<HomeRoute>(
  path: '/',
  routes: <TypedGoRoute<GoRouteData>>[
    TypedGoRoute<OneRoute>(path: 'OneRoute', routes: [
      TypedGoRoute<TwoRoute>(
        path: 'TwoRoute',
      )
    ])
  ],
)
class HomeRoute extends GoRouteData {
  const HomeRoute();

  @override
  Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}

class OneRoute extends GoRouteData {
  final ExtraParam $extra;

  const OneRoute({required this.$extra});

  @override
  Widget build(BuildContext context, GoRouterState state) => OneScreen(extra: $extra);
}

class TwoRoute extends GoRouteData {
  const TwoRoute();

  @override
  Widget build(BuildContext context, GoRouterState state) => const TwoScreen();
}

```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details><summary>Logs</summary>

```console
E/flutter (13571): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'ExtraParam' in type cast
E/flutter (13571): #0      $OneRouteExtension._fromState (package:untiled/main.g.dart:47:29)
E/flutter (13571): #1      GoRouteData.$route.factoryImpl (package:go_router/src/route_data.dart:96:53)
E/flutter (13571): #2      GoRouteData.$route.redirect (package:go_router/src/route_data.dart:106:9)
E/flutter (13571): #3      _getRouteLevelRedirect (package:go_router/src/redirection.dart:136:42)
E/flutter (13571): #4      _getRouteLevelRedirect.processRouteRedirect (package:go_router/src/redirection.dart:131:7)
E/flutter (13571): #5      _getRouteLevelRedirect (package:go_router/src/redirection.dart:154:12)
E/flutter (13571): #6      redirect.processRedirect.processTopLevelRedirect (package:go_router/src/redirection.dart:81:11)
E/flutter (13571): #7      redirect.processRedirect (package:go_router/src/redirection.dart:108:14)
E/flutter (13571): #8      SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:41:35)
E/flutter (13571): #9      redirect (package:go_router/src/redirection.dart:116:30)
E/flutter (13571): #10     GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:98:65)
E/flutter (13571): #11     GoRouter.push (package:go_router/src/router.dart:236:39)
E/flutter (13571): #12     GoRouterHelper.push (package:go_router/src/misc/extensions.dart:48:25)
E/flutter (13571): #13     $TwoRouteExtension.push (package:untiled/main.g.dart:72:55)
E/flutter (13571): #14     OneScreen.build.<anonymous closure> (package:untiled/main.dart:61:24)
E/flutter (13571): #15     _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1072:21)
E/flutter (13571): #16     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
E/flutter (13571): #17     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:627:11)
E/flutter (13571): #18     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:306:5)
E/flutter (13571): #19     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:239:7)
E/flutter (13571): #20     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:615:9)
E/flutter (13571): #21     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
E/flutter (13571): #22     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:143:9)
E/flutter (13571): #23     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
E/flutter (13571): #24     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
E/flutter (13571): #25     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
E/flutter (13571): #26     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:460:19)
E/flutter (13571): #27     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
E/flutter (13571): #28     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:337:11)
E/flutter (13571): #29     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
E/flutter (13571): #30     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
E/flutter (13571): #31     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
E/flutter (13571): #32     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (13571): #33     _invoke1 (dart:ui/hooks.dart:167:13)
E/flutter (13571): #34     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:341:7)
E/flutter (13571): #35     _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
E/flutter (13571): 

```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.3.1 22E772610a darwin-x64, locale ru-RU)
    • Flutter version 3.3.10 on channel stable at /Users/olegm/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (5 months ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/olegm/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/olegm/Library/Android/sdk
    • Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Connected device (3 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • macOS (desktop)         • macos         • darwin-x64     • macOS 13.3.1 22E772610a darwin-x64
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 113.0.5672.92

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
Process finished with exit code 0
```

</details>