Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!pageKeyToOldEntry.containsKey(page.key) when navigating between nested routes with stacked routes #189

Open
saibotma opened this issue Apr 16, 2022 · 0 comments

Comments

@saibotma
Copy link

saibotma commented Apr 16, 2022

Steps to reproduce:

  1. Run the example code below
  2. Start on /home/dashboard → click on "to /home/dashboard/settings" → click on "to /home/content/settings" → click on "to /home/dashboard/settings" → click on "to /home/content/settings"
  3. Take a look at the console (not browser console) and see the following exception:
The following assertion was thrown building Builder:
Assertion failed: file:///Users/xx/Documents/Dev/Tools/flutter/packages/flutter/lib/src/widgets/navigator.dart:3656:14
!pageKeyToOldEntry.containsKey(page.key)
is not true

The relevant error-causing widget was: 
  Expanded Expanded:file:///Users/xx/Documents/Dev/drafts/xx/lib/vrouter_key_issue.dart:95:9
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 4943:57                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 5787:32                           updateChildren
packages/flutter/src/widgets/framework.dart 6445:17                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 5787:32                           updateChildren
packages/flutter/src/widgets/framework.dart 6445:17                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/inherited_notifier.dart 111:11                   update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4834:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 6291:14                           update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 5108:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 4960:5                            update
packages/flutter/src/widgets/framework.dart 3501:14                           updateChild
packages/flutter/src/widgets/framework.dart 4780:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 2659: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>

The exception gets also thrown when you don't navigate quickly. Thus i believe that this is not a duplicate of #170, #91, #84 and #77.

Flutter version: 2.10.4

Example code
import 'package:flutter/material.dart';
import 'package:vrouter/vrouter.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return VRouter(
      initialUrl: "/home/dashboard",
      routes: [
        VNester(
          key: const ValueKey("home"),
          path: "/home",
          widgetBuilder: (child) => HomePage(child: child),
          nestedRoutes: [
            VWidget(
              key: const ValueKey("dashboard"),
              path: "dashboard",
              aliases: ["dashboard/settings"],
              widget: Page(
                name: "Dashboard",
                routeTo: ["/home/dashboard/settings"],
                color: Colors.purple,
              ),
            ),
            VWidget(
              key: const ValueKey("content"),
              path: "content",
              aliases: ["content/settings"],
              widget: Page(
                name: "content",
                color: Colors.red,
                routeTo: ["/home/content/settings"],
              ),
            ),
          ],
          stackedRoutes: [
            VSinglePopHandler(
                onPop: (redirector) async {
                  redirector.to("/home/dashboard");
                },
                stackedRoutes: [
                  VWidget(
                    key: const ValueKey("dashboardSettings"),
                    path: "dashboard/settings",
                    widget: Page(
                      name: "Dashboard Settings",
                      routeTo: ["/home/content/settings"],
                      color: Colors.yellow,
                    ),
                  ),
                ]),
            VSinglePopHandler(
              onPop: (redirector) async {
                redirector.to("/home/content");
              },
              stackedRoutes: [
                VWidget(
                  key: const ValueKey("contentSettings"),
                  path: "/home/content/settings",
                  widget: Page(
                    name: "Content Settings",
                    color: Colors.blue,
                    routeTo: ["/home/dashboard/settings"],
                  ),
                )
              ],
            )
          ],
        )
      ],
    );
  }
}

class HomePage extends StatelessWidget {
  final Widget child;

  HomePage({required this.child, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(child: child),
        Container(height: 100, color: Colors.blue),
      ],
    );
  }
}

class Page extends StatelessWidget {
  final String name;
  final List<String> routeTo;
  final Color color;

  const Page({
    required this.name,
    this.routeTo = const [],
    required this.color,
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: color,
        alignment: Alignment.center,
        child: Column(
          children: [
            Text(
              name,
              style: const TextStyle(fontSize: 100),
            ),
            ...routeTo.map((e) {
              return ElevatedButton(
                onPressed: () => context.vRouter.to(e),
                child: Text("to $e"),
              );
            })
          ],
        ),
      ),
    );
  }
}

class VSinglePopHandler extends VRouteElementBuilder {
  final List<VRouteElement> stackedRoutes;
  final Future<void> Function(VRedirector vRedirector) _onPop;

  VSinglePopHandler({
    required Future<void> Function(VRedirector vRedirector) onPop,
    required this.stackedRoutes,
  }) : _onPop = onPop;

  @override
  List<VRouteElement> buildRoutes() => stackedRoutes;

  @override
  Future<void> onPop(VRedirector vRedirector) => _onPop(vRedirector);

  @override
  Future<void> onSystemPop(VRedirector vRedirector) => _onPop(vRedirector);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant