Repository navigation
[Navigator 2.0]Failed assertion: line 3630 pos 14: '!pageKeyToOldEntry.containsKey(page.key)': is not true. #97363
Copy link
Copy link
Closed
Labels
f: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.8Found to occur in 2.8Found to occur in 2.8frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Steps to Reproduce
- Execute
flutter runon the code sample - 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
f: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.8Found to occur in 2.8Found to occur in 2.8frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Activity
maheshj01 commentedon Jan 27, 2022
Hi @urusai88, Thanks for filing the issue. I am able to reproduce the issue on stable and the master channel,
flutter doctor -v
IOS logs
chrome logs
cc: @chunhtai
[-]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.[/+]urusaich commentedon Jan 27, 2022
@maheshmnj found a possible workaround
code
HansMuller commentedon Jan 27, 2022
CC @chunhtai
chunhtai commentedon Jan 27, 2022
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
github-actions commentedon Feb 14, 2022
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 -vand a minimal reproduction of the issue.