Skip to content

[Navigator 2.0]Failed assertion: line 3630 pos 14: '!pageKeyToOldEntry.containsKey(page.key)': is not true. #97363

Closed

Description

@urusaich

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Tap on ElevatedButtons as fast as possible

Expected results: No crash

Actual results: Crash with errors

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

class AppLink {
  final bool home;

  const AppLink({required this.home});
}

class AppRouteInformationParser extends RouteInformationParser<AppLink> {
  @override
  Future<AppLink> parseRouteInformation(RouteInformation routeInformation) async => const AppLink(home: true);
}

class AppRouterDelegate extends RouterDelegate<AppLink> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
  AppLink appLink = const AppLink(home: true);

  @override
  GlobalKey<NavigatorState> navigatorKey = GlobalKey();

  @override
  Future<void> setNewRoutePath(AppLink configuration) async {
    appLink = configuration;
    notifyListeners();
  }

  @override
  Widget build(BuildContext context) {
    final pages = <Page>[];

    if (appLink.home) {
      pages.add(
        CupertinoPage(
          key: const ValueKey('home'),
          child: Scaffold(
            body: Center(
              child: ElevatedButton(
                onPressed: () => setNewRoutePath(const AppLink(home: false)),
                child: const Text('TO 2'),
              ),
            ),
          ),
        ),
      );
    }

    if (!appLink.home) {
      pages.add(
        CupertinoPage(
          key: const ValueKey('not home'),
          child: Scaffold(
            body: Center(
              child: ElevatedButton(
                onPressed: () => setNewRoutePath(const AppLink(home: true)),
                child: const Text('TO 1'),
              ),
            ),
          ),
        ),
      );
    }

    return Navigator(
      key: navigatorKey,
      pages: pages,
      onPopPage: (route, result) => route.didPop(result),
    );
  }
}

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      routerDelegate: AppRouterDelegate(),
      routeInformationParser: AppRouteInformationParser(),
    );
  }
}
Logs
E/flutter ( 8285): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3767 pos 12: '_debugLocked && !_debugUpdatingPage': is not true.
E/flutter ( 8285): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)
E/flutter ( 8285): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter ( 8285): #2      NavigatorState._flushHistoryUpdates (package:flutter/src/widgets/navigator.dart:3767:12)
E/flutter ( 8285): #3      _RouteEntry.handlePush.<anonymous closure> (package:flutter/src/widgets/navigator.dart:2843:21)
E/flutter ( 8285): #4      TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart:407:15)
E/flutter ( 8285): #5      _rootRunUnary (dart:async/zone.dart:1436:47)
E/flutter ( 8285): #6      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter ( 8285): <asynchronous suspension>
E/flutter ( 8285): #7      TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart)
E/flutter ( 8285): <asynchronous suspension>
E/flutter ( 8285): 

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Builder:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3630 pos 14: '!pageKeyToOldEntry.containsKey(page.key)': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was: 
  MaterialApp MaterialApp:file:///C:/code/jitsi/navigator_test/lib/main.dart:80:24
When the exception was thrown, this was the stack: 
#2      NavigatorState._updatePages (package:flutter/src/widgets/navigator.dart:3630:14)
#3      NavigatorState.didUpdateWidget (package:flutter/src/widgets/navigator.dart:3433:7)
#4      StatefulElement.update (package:flutter/src/widgets/framework.dart:4778:57)
#5      Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4613:16)
#7      Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#8      StatelessElement.update (package:flutter/src/widgets/framework.dart:4669:5)
#9      Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#10     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4613:16)
#11     Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#12     ProxyElement.update (package:flutter/src/widgets/framework.dart:4943:5)
#13     Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#14     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4613:16)
#15     Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#16     ProxyElement.update (package:flutter/src/widgets/framework.dart:4943:5)
#17     Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#18     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4613:16)
#19     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4763:11)
#20     Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#21     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2578:33)
#22     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#23     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#24     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#25     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#26     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#30     _invoke (dart:ui/hooks.dart:150:10)
#31     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#32     _drawFrame (dart:ui/hooks.dart:114:31)
(elided 5 frames from class _AssertionError and dart:async)
====================================================================================================

Analyzing navigator_test...
No issues found! (ran in 2.5s)
[√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.19043.1348], locale ru-RU)
    • Flutter version 2.8.1 at C:\Tools\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (6 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\User\AppData\Local\Android\Sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = C:\Users\User\AppData\Local\Android\Sdk
    • ANDROID_SDK_ROOT = C:\Users\User\AppData\Local\Android\Sdk
    • Java binary at:
      C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\203.7784292\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.5)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31729.503
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\203.7784292
    • Flutter plugin version 63.2.1
    • Dart plugin version 203.8452
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\IDEA-C\ch-0\212.5284.40
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 212.5632

[√] Connected device (4 available)
    • M2102J20SG (mobile) • 524cd19c • android-arm64  • Android 11 (API 30)
    • Windows (desktop)   • windows  • windows-x64    • Microsoft Windows [Version 10.0.19043.1348]
    • Chrome (web)        • chrome   • web-javascript • Google Chrome 97.0.4692.71
    • Edge (web)          • edge     • web-javascript • Microsoft Edge 97.0.1072.69

• No issues found!
video_2022-01-27_14-36-35.mp4

Activity

  1. maheshj01 commented on Jan 27, 2022

    @maheshj01
    Member

    Hi @urusai88, Thanks for filing the issue. I am able to reproduce the issue on stable and the master channel,

    flutter doctor -v
    [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.8.1 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800
        • Engine revision 890a5fca2e
        • Dart version 2.15.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.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
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 60.1.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.32.0
    
    [✓] Connected device (4 available)
        • Redmi K20 Pro (mobile) • 192.168.1.3:5555                     • android-arm64  • Android 11 (API 30)
        • iPhone 13 Pro (mobile) • 0FA2FB93-2A89-4FDB-8293-DF66188F1E54 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0
          (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 96.0.4664.110
    
    • No issues found!
    
    [✓] Flutter (Channel master, 2.10.0-1.0.pre.307, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.10.0-1.0.pre.307 at /Users/mahesh/Documents/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b7424c619c (7 hours ago), 2022-01-26 17:25:45 -0800
        • Engine revision c248c6e38e
        • Dart version 2.17.0 (build 2.17.0-63.0.dev)
        • DevTools version 2.10.0-dev.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.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
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 60.1.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.32.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)    • chrome • web-javascript • Google Chrome 97.0.4692.99
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    IOS logs
    Running "flutter pub get" in example...
    Launching lib/main.dart on iPhone 12 Pro in debug mode...
    Warning: Missing build name (CFBundleShortVersionString).
    Warning: Missing build number (CFBundleVersion).
    Action Required: You must set a build name and number in the pubspec.yaml file version field before submitting to the App Store.
    Xcode build done.                                           65.6s
    Connecting to VM Service at ws://127.0.0.1:58509/UzS3gUbQNqc=/ws
    
    ════════ Exception caught by widgets library ═══════════════════════════════════
    The following assertion was thrown building Builder:
    'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3630 pos 14: '!pageKeyToOldEntry.containsKey(page.key)': is not true.
    
    Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
    In either case, please report this assertion by filing a bug on GitHub:
      https://github.com/flutter/flutter/issues/new?template=2_bug.md
    
    The relevant error-causing widget was
    MaterialApp
    When the exception was thrown, this was the stack
    #2      NavigatorState._updatePages
    #3      NavigatorState.didUpdateWidget
    #4      StatefulElement.update
    #5      Element.updateChild
    #6      ComponentElement.performRebuild
    #7      Element.rebuild
    #8      StatelessElement.update
    #9      Element.updateChild
    #10     ComponentElement.performRebuild
    #11     Element.rebuild
    #12     ProxyElement.update
    #13     Element.updateChild
    #14     ComponentElement.performRebuild
    #15     Element.rebuild
    #16     ProxyElement.update
    #17     Element.updateChild
    #18     ComponentElement.performRebuild
    #19     StatefulElement.performRebuild
    #20     Element.rebuild
    #21     BuildOwner.buildScope
    #22     WidgetsBinding.drawFrame
    #23     RendererBinding._handlePersistentFrameCallback
    #24     SchedulerBinding._invokeFrameCallback
    #25     SchedulerBinding.handleDrawFrame
    #26     SchedulerBinding._handleDrawFrame
    #30     _invoke (dart:ui/hooks.dart:150:10)
    #31     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
    #32     _drawFrame (dart:ui/hooks.dart:114:31)
    (elided 5 frames from class _AssertionError and dart:async)
    ════════════════════════════════════════════════════════════════════════════════
    [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3767 pos 12: '_debugLocked && !_debugUpdatingPage': is not true.
    #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)
    #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
    #2      NavigatorState._flushHistoryUpdates
    #3      _RouteEntry.handlePush.<anonymous closure>
    #4      TickerFuture.whenCompleteOrCancel.thunk
    #5      _rootRunUnary (dart:async/zone.dart:1436:47)
    #6      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
    <asynchronous suspension>
    #7      TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart)
    <asynchronous suspension>
    
    
    chrome logs
    mahesh@Maheshs-MacBook-Air-M1 example % flutterm run -d chrome
    Running "flutter pub get" in example...                          2,193ms
    Launching lib/main.dart on Chrome in debug mode...
    Waiting for connection from debug service on Chrome...             22.5s
    This app is linked to the debug service: ws://127.0.0.1:58352/I41UqPQH-N4=/ws
    Debug service listening on ws://127.0.0.1:58352/I41UqPQH-N4=/ws
    
    💪 Running with sound null safety 💪
    
    🔥  To hot restart changes while running, press "r" or "R".
    For a more detailed help message, press "h". To quit, press "q".
    
    An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:58352/I41UqPQH-N4=
    The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:58352/I41UqPQH-N4=
    ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
    The following assertion was thrown building Builder:
    Assertion failed:
    file:///Users/mahesh/Documents/flutter_master/packages/flutter/lib/src/widgets/navigator.dart:3656:14
    !pageKeyToOldEntry.containsKey(page.key)
    is not true
    
    The relevant error-causing widget was:
      MaterialApp MaterialApp:file:///Users/mahesh/Desktop/web_hid.dart/example/lib/main.dart:83:24
    
    When the exception was thrown, this was the stack:
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
    packages/flutter/src/widgets/navigator.dart 3656:49                           [_updatePages]
    packages/flutter/src/widgets/navigator.dart 3457:7                            didUpdateWidget
    packages/flutter/src/widgets/framework.dart 4977:57                           update
    packages/flutter/src/widgets/framework.dart 3534:14                           updateChild
    packages/flutter/src/widgets/framework.dart 4814:16                           performRebuild
    packages/flutter/src/widgets/framework.dart 4511:5                            rebuild
    packages/flutter/src/widgets/framework.dart 4868:5                            update
    packages/flutter/src/widgets/framework.dart 3534:14                           updateChild
    packages/flutter/src/widgets/framework.dart 4814:16                           performRebuild
    packages/flutter/src/widgets/framework.dart 4511:5                            rebuild
    packages/flutter/src/widgets/framework.dart 5142:5                            update
    packages/flutter/src/widgets/framework.dart 3534:14                           updateChild
    packages/flutter/src/widgets/framework.dart 4814:16                           performRebuild
    packages/flutter/src/widgets/framework.dart 4511:5                            rebuild
    packages/flutter/src/widgets/framework.dart 5142:5                            update
    packages/flutter/src/widgets/framework.dart 3534:14                           updateChild
    packages/flutter/src/widgets/framework.dart 4814:16                           performRebuild
    packages/flutter/src/widgets/framework.dart 4962:11                           performRebuild
    packages/flutter/src/widgets/framework.dart 4511:5                            rebuild
    packages/flutter/src/widgets/framework.dart 2713:18                           buildScope
    packages/flutter/src/widgets/binding.dart 882:9                               drawFrame
    packages/flutter/src/rendering/binding.dart 363:5                             [_handlePersistentFrameCallback]
    packages/flutter/src/scheduler/binding.dart 1144:15                           [_invokeFrameCallback]
    packages/flutter/src/scheduler/binding.dart 1081:9                            handleDrawFrame
    packages/flutter/src/scheduler/binding.dart 995:5                             [_handleDrawFrame]
    lib/_engine/engine/platform_dispatcher.dart 1011:13                           invoke
    lib/_engine/engine/platform_dispatcher.dart 159:5                             invokeOnDrawFrame
    lib/_engine/engine/initialization.dart 128:45                                 <fn>
    
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    Error: Assertion failed: file:///Users/mahesh/Documents/flutter_master/packages/flutter/lib/src/widgets/navigator.dart:3795:12
    _debugLocked && !_debugUpdatingPage
    is not true
        at Object.throw_ [as throw] (http://localhost:58315/dart_sdk.js:5069:11)
        at Object.assertFailed (http://localhost:58315/dart_sdk.js:4994:15)
        at navigator$.NavigatorState.new.[_flushHistoryUpdates]
        (http://localhost:58315/packages/flutter/src/widgets/widget_inspector.dart.lib.js:21240:74)
        at http://localhost:58315/packages/flutter/src/widgets/widget_inspector.dart.lib.js:20370:47
        at thunk (http://localhost:58315/packages/flutter/src/scheduler/ticker.dart.lib.js:297:9)
        at _RootZone.runUnary (http://localhost:58315/dart_sdk.js:40442:59)
        at _FutureListener.then.handleValue (http://localhost:58315/dart_sdk.js:35364:29)
        at handleValueCallback (http://localhost:58315/dart_sdk.js:35932:49)
        at Function._propagateToListeners (http://localhost:58315/dart_sdk.js:35970:17)
        at _Future.new.[_completeWithValue] (http://localhost:58315/dart_sdk.js:35818:23)
        at async._AsyncCallbackEntry.new.callback (http://localhost:58315/dart_sdk.js:35839:35)
        at Object._microtaskLoop (http://localhost:58315/dart_sdk.js:40709:13)
        at _startMicrotaskLoop (http://localhost:58315/dart_sdk.js:40715:13)
        at http://localhost:58315/dart_sdk.js:36192:9
    Application finished.
    mahesh@Maheshs-MacBook-Air-M1 example % 

    cc: @chunhtai

  2. added
    f: routesNavigator, Router, and related APIs.
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Jan 27, 2022
  3. changed the title [-]Assert errors when using navigator 2.0 and fast switching between two pages[/-] [+][Navigator 2.0]Failed assertion: line 3630 pos 14: '!pageKeyToOldEntry.containsKey(page.key)': is not true.[/+] on Jan 27, 2022
  4. urusaich commented on Jan 27, 2022

    @urusaich
    Author

    @maheshmnj found a possible workaround

    code
    class AppLinkKey extends UniqueKey {
      AppLinkKey(this.appLink);
    
      final AppLink appLink;
    
      @override
      String toString() => 'AppLinkKey($appLink)[#${shortHash(this)}]';
    }
    
    class AppLink {
      final bool home;
      late final key = AppLinkKey(this);
    
      AppLink({required this.home});
    }
    
    class AppRouteInformationParser extends RouteInformationParser<AppLink> {
      @override
      Future<AppLink> parseRouteInformation(RouteInformation routeInformation) async => AppLink(home: true);
    }
    
    class AppRouterDelegate extends RouterDelegate<AppLink> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
      AppLink appLink = AppLink(home: true);
    
      @override
      GlobalKey<NavigatorState> navigatorKey = GlobalKey();
    
      @override
      Future<void> setNewRoutePath(AppLink configuration) async {
        appLink = configuration;
        notifyListeners();
      }
    
      @override
      Widget build(BuildContext context) {
        final pages = <Page>[];
    
        if (appLink.home) {
          pages.add(
            CupertinoPage(
              key: appLink.key,
              child: Scaffold(
                body: Center(
                  child: ElevatedButton(
                    onPressed: () => setNewRoutePath(AppLink(home: false)),
                    child: const Text('TO 2'),
                  ),
                ),
              ),
            ),
          );
        }
    
        if (!appLink.home) {
          pages.add(
            CupertinoPage(
              key: appLink.key,
              child: Scaffold(
                body: Center(
                  child: ElevatedButton(
                    onPressed: () => setNewRoutePath(AppLink(home: true)),
                    child: const Text('TO 1'),
                  ),
                ),
              ),
            ),
          );
        }
    
        return Navigator(
          key: navigatorKey,
          pages: pages,
          onPopPage: (route, result) => route.didPop(result),
        );
      }
    }
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp.router(
          title: 'Flutter Demo',
          routerDelegate: AppRouterDelegate(),
          routeInformationParser: AppRouteInformationParser(),
        );
      }
    }
  5. HansMuller commented on Jan 27, 2022

    @HansMuller
    Contributor
  6. self-assigned this
    on Jan 27, 2022
  7. chunhtai commented on Jan 27, 2022

    @chunhtai
    Contributor

    it will crash If you press it three times before the first page finishing popping. It will be easier to trigger if you increase the transition duration. This is due to the popping route won't leave the route stack until it finishes popping, so you will end up with routes that have same page keys. I will put up a fix shortly

  8. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jan 31, 2022
  9. github-actions commented on Feb 14, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

f: routesNavigator, Router, and related APIs.found in release: 2.10Found to occur in 2.10found in release: 2.8Found to occur in 2.8frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: 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