Skip to content

[go_router] Using .push instead of .go causes extra to be always null in .routerDelegate.currentConfiguration (When using ShellRoute) #148215

@Wegi

Description

@Wegi

Steps to reproduce

Use a GoRouter with a ShellRoute and some child routes. Then use .push instead of .go to havigate to a child route with extras passed.

When .go is used

_goRouter.routerDelegate.currentConfiguration.extra is properly filled. When push is used with the same code it is null.

Expected results

The expected result would be for the extra to be filled similar in both .push and .go cases.

Actual results

Extra is null in currentConfiguration, when using .push.

Code sample

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

void main() {
  runApp(const MyApp());
}

final GoRouter goRouter = GoRouter(
  initialLocation: '/',
  routes: <RouteBase>[
    ShellRoute(
      builder: (BuildContext context, GoRouterState state, Widget child) {
        return Scaffold(
          body: SafeArea(
            child: Padding(
              padding: const EdgeInsets.symmetric(vertical: 8.0),
              child: child,
            ),
          ),
        );
      },
      routes: <RouteBase>[
        GoRoute(
          path: '/',
          name: 'home',
          builder: (context, state) => Container(
              child: TextButton(
            onPressed: () {
              context.push('/extra', extra: {'foo': 'bar'});
            },
            child: Text('Pass extra'),
          )),
        ),
        GoRoute(
            path: '/extra',
            name: 'extra route',
            builder: (context, state) {
              final Map<String, Object> extra = state.extra! as Map<String, String>;
              final String foo = extra["foo"]! as String;

              final Map<String, Object> globalExtra =
                  (goRouter.routerDelegate.currentConfiguration.extra as Map<String, String>?) ?? {};
              final String? globalFoo = globalExtra["foo"] as String?;

              return Container(
                child: Column(
                  children: [Text("Extra passed: $foo"), Text("Extra in configuration: $globalFoo")],
                ),
              );
            }),
      ],
    )
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      routerConfig: goRouter,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
flutter doctor -v
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.3.1 23D60 darwin-arm64, locale de-DE)
    • Flutter version 3.16.9 on channel stable at /Users/wegi/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (vor 4 Monaten), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/wegi/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/wegi/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Users/wegi/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
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1.1)
    • IntelliJ at /Users/wegi/Applications/IntelliJ IDEA Ultimate.app
    • 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

[✓] Connected device (4 available)
    • iPhone von Alexander (mobile) • 00008130-000A64562491401C            • ios            • iOS 17.4.1 21E236
    • iPhone 15 Pro (mobile)        • 40DFC392-3D2C-4D47-9D36-0D31486C5DFE • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)               • macos                                • darwin-arm64   • macOS 14.3.1 23D60
      darwin-arm64
    • Chrome (web)                  • chrome                               • web-javascript • Google Chrome
      124.0.6367.158

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions