[go_router] NavigatorObserver route.settings is null for pageBuilder routes in 5.0.1

This issue has been created since 2022-09-22.

Steps to Reproduce

You can run the app at https://github.com/jonmountjoy/bug_nav

If you navigate to any route that is constructed with a builder, such as:

GoRoute(
            name: 'page2',
            path: 'page2/:p1',
            builder: .... )

Then a navigation observer didPush has the route.settings setup just fine, and you can determine the name of the route, and other details.

If you navigate to any route that is constructed with a pageBuilder, such as:

GoRoute(
            name: 'page2alternative',
            path: 'page2alternative/:p1',
            pageBuilder: (BuildContext context, GoRouterState state) =>
                const NoTransitionPage<void>(
                    child: Page2Screen(name: "alternative")),
          ),

Then a navigation observer didPush has the route.settings set to null.

Expected results:

I expect the navigation observer to allow me to observe all routes.
My intent is to send all navigated routes to Google Analytics.

Actual results:

There's not enough information in the navigation observer.

jonmountjoy wrote this answer on 2022-09-22

Also, you can't use the swipe gesture to navigate back, on pageBuilder routes, only on builder routes 🤷

exaby73 wrote this answer on 2022-09-22

Hello @jonmountjoy. Thank you for filing this issue. Can you please provide the following information?

jonmountjoy wrote this answer on 2022-09-22

Hi @exaby73

See the first line for the example.

Here we go with the doctor output. Thank you.

flutter doctor -v [✓] Flutter (Channel stable, 3.3.2, on macOS 12.6 21G115 darwin-x64, locale en-GB) • Flutter version 3.3.2 on channel stable at /Users/jonmountjoy/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision e3c29ec (8 days ago), 2022-09-14 08:46:55 -0500 • Engine revision a4ff2c53d8 • Dart version 2.18.1 • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/jonmountjoy/Library/Android/sdk
• Platform android-33, build-tools 30.0.3
• ANDROID_HOME = /Users/jonmountjoy/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14A309
• CocoaPods version 1.11.3

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

exaby73 wrote this answer on 2022-09-23

Triage Report

Versions reproducible on

  • Stable (3.3.2): go_router: 5.0.1
  • Master (3.4.0-28.0.pre.123): go_router: 5.0.1

Info

Logs
flutter: [INFO] MyNavObserver: didPush: route(null: null), previousRoute= route(/: {q1: qv1})
Code Sample
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';

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

/// The main app.
class App extends StatelessWidget {
  /// Creates an [App].
  App({Key? key}) : super(key: key);

  /// The title of the app.
  static const String title = 'GoRouter Example: Navigator Observer';

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

  final GoRouter _router = GoRouter(
    observers: <NavigatorObserver>[MyNavObserver()],
    routes: <GoRoute>[
      GoRoute(
        // if there's no name, path will be used as name for observers
        path: '/',
        builder: (BuildContext context, GoRouterState state) =>
            const Page1Screen(),
        routes: <GoRoute>[
          GoRoute(
            name: 'page2',
            path: 'page2/:p1',
            builder: (BuildContext context, GoRouterState state) =>
                const Page2Screen(name: "standard"),
          ),
          GoRoute(
            name: 'page2alternative',
            path: 'page2alternative/:p1',
            pageBuilder: (BuildContext context, GoRouterState state) =>
                const NoTransitionPage<void>(
                    child: Page2Screen(name: "alternative")),
          ),
        ],
      ),
    ],
  );
}

/// The Navigator observer.
class MyNavObserver extends NavigatorObserver {
  /// Creates a [MyNavObserver].
  MyNavObserver() {
    log.onRecord.listen((LogRecord e) => debugPrint('$e'));
  }

  /// The logged message.
  final Logger log = Logger('MyNavObserver');

  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    log.info('didPush: ${route.str}, previousRoute= ${previousRoute?.str}');
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) =>
      log.info('didPop: ${route.str}, previousRoute= ${previousRoute?.str}');

  @override
  void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) =>
      log.info('didRemove: ${route.str}, previousRoute= ${previousRoute?.str}');

  @override
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) =>
      log.info('didReplace: new= ${newRoute?.str}, old= ${oldRoute?.str}');
}

extension on Route<dynamic> {
  String get str => 'route(${settings.name}: ${settings.arguments})';
}

/// The screen of the first page.
class Page1Screen extends StatelessWidget {
  /// Creates a [Page1Screen].
  const Page1Screen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: const Text(App.title)),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                onPressed: () => context.goNamed(
                  'page2',
                  params: <String, String>{'p1': 'pv1'},
                  queryParams: <String, String>{'q1': 'qv1'},
                ),
                child: const Text('Go to page 2'),
              ),
              ElevatedButton(
                onPressed: () => context.goNamed(
                  'page2alternative',
                  params: <String, String>{'p1': 'pv1'},
                  queryParams: <String, String>{'q1': 'qv1'},
                ),
                child: const Text('Go to page 2 alternative'),
              ),
            ],
          ),
        ),
      );
}

/// The screen of the second page.
class Page2Screen extends StatelessWidget {
  final String name;

  /// Creates a [Page2Screen].
  const Page2Screen({required this.name, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: const Text(App.title)),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("Welcome to Page 2 $name"),
              const Text("You have arrived."),
            ],
          ),
        ),
      );
}

Flutter Doctor

flutter doctor -v (Stable)
[✓] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.22000.978], locale en-US)
    • Flutter version 3.3.2 on channel stable at C:\Users\Nabeel\fvm\versions\stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e3c29ec00c (9 days ago), 2022-09-14 08:46:55 -0500
    • Engine revision a4ff2c53d8
    • Dart version 2.18.1
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\android-sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.2)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.3.32819.101
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.12+7-b1504.28-7817840)

[✓] VS Code (version 1.71.2)
    • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.46.0

[✓] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.978]
    • Chrome (web)                 • chrome        • web-javascript • unknown
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 105.0.1343.42

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
flutter doctor -v (Master)
[✓] Flutter (Channel master, 3.4.0-28.0.pre.123, on Microsoft Windows [Version 10.0.22000.978], locale en-US)
    • Flutter version 3.4.0-28.0.pre.123 on channel master at C:\Users\Nabeel\fvm\versions\master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4aa27d844e (6 hours ago), 2022-09-22 21:00:22 -0700
    • Engine revision a5489ce4f9
    • Dart version 2.19.0 (build 2.19.0-229.0.dev)
    • DevTools version 2.17.0

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\android-sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.2)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.3.32819.101
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.12+7-b1504.28-7817840)

[✓] VS Code (version 1.71.2)
    • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.46.0

[✓] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.978]
    • Chrome (web)                 • chrome        • web-javascript • unknown
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 105.0.1343.42

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-10-05
Star Count 145512
Watcher Count 3569
Fork Count 23398
Issue Count 11205

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Banner + Navbar height 2 2021-04-13 2022-07-17
The parameter --role-arn isn't working 2 2019-10-08 2022-09-19
FR: add a "isPlayedLive" flag to the flags part of MIDI events 2 2021-12-25 2022-06-11
Investigate plugin fx gui embedded in the track mixer 0 2021-12-23 2022-08-18
Add support for CockroachDB 0 2021-04-29 2022-09-08
Loss of eigenvectors' sign information 0 2021-10-09 2022-07-22
基于Github Action自动生成并更新GitHub Issue博客的ReadMe 27 2019-04-30 2022-05-08
解决: ssh 远程登录虚拟机 Linux 速度很慢的问题 0 2019-11-08 2022-05-08
How to obtain frame timestamp? 3 2021-03-17 2022-09-24
Connecting to SQL DB over psycopg2 throws timeout 2 2022-07-12 2022-10-02
为什么一定要加上 `time.Sleep` 2 2021-03-17 2022-08-17
[Suggestion] Keybind for switching animated texture frames 2 2021-12-03 2022-09-18
No SecondLayer 1 2021-12-08 2022-01-11
REAPER + VST3 + Linux + Resize => memory corruption 11 2021-09-05 2022-08-06
Documentation for Perpetual MM strategy 0 2021-12-01 2021-11-29
Add Primus Core Dump Loader 0 2016-06-27 2022-09-28
Set up integration tests using PySTAC Client or a similar tool 4 2021-07-28 2022-09-27
"This type cannot unbox to a native integer: P6opaque, Whatever" where no WhateverCode is used 4 2022-03-18 2022-08-31
status shows wrong version 1 2022-02-12 2022-04-05
Using ngx-toastr 2 2021-01-27 2022-01-12
iOS移动端页面footer位置偏移 0 2021-07-18 2021-11-28
Use custom exceptions 0 2021-07-19 2022-08-12
Replacement for shortcode docs links 6 2021-11-23 2022-09-15
Support for Haxe 4.2.0? [Module level statics] 1 2021-03-01 2022-09-01
Burst priority of the collecting thread 0 2022-09-23 2022-10-03
[RFE]: port knock to get sending public ip unblocked? 1 2022-05-13 2022-10-03
Fail2Ban doesn't use "sender" parameter in jail.local for sending emails 4 2022-05-23 2022-09-22
how to boost insert select from remote table 1 2021-10-21 2022-10-04
[ProjectAPI] Add `--target-dir` to `clean`, `run`, `doc` command 0 2021-11-25 2021-12-21
provide link to built-in role for minimum permissions needed to run deployment script 2 2022-02-01 2022-07-20
Unexpected version format error when testing Data Fabric (Mapr) 6.2.0 Database 0 2022-03-02 2022-09-26
Win32 vs arm64 (Apple M1) returning different serialized data type 4 2021-11-05 2022-09-15
Add this .ebextension to allow most of the AWS provided ones to run on Amazon Linux v2 2 2020-06-05 2022-04-17
After profiling some columns are not showed 1 2021-09-30 2022-09-15
[Website] Seemingly duplicate samples on the samples page 0 2021-09-23 2022-08-04
Add k6 extensions support 2 2021-05-26 2022-10-05
Unable to compile on CrowPi2 3 2021-09-12 2022-09-15
[Add request] 0 2021-10-25 2022-01-15
Connect running dev mode process to IntelliJ debugger 1 2021-03-12 2022-09-20
Flash of unstyled content (FOUC) in recent Firefox versions 1 2022-07-08 2022-08-30
build-plugin-esbuild 问题 1 2021-08-18 2022-08-31
HP Laser MFP 135A driver issue 1 2020-12-26 2022-07-31
无法连接到aria2 5 2021-10-23 2022-01-20
Two tests failed after successful compilation by msvc on the windows x64 platform 3 2021-11-09 2022-09-29
WinUI3 client and package plans? 2 2021-08-20 2022-09-20
Run `melos bootstrap` fails when using `PUB_HOSTED_URL` 4 2021-03-30 2022-08-24
Adding Server Reflection/Usage with gRPCurl 1 2022-09-01 2022-09-24
PFFile problem 5 2016-04-03 2022-01-23
RBAC Error for Bare-Metal deployment YAML file. 11 2021-09-24 2022-01-28
Rounded corners, when used with borders, cause elements to be invisible 1 2022-04-16 2022-09-25