Search code examples
fluttererror-handlingnavigation

I am reaching an assertion fail error in errors_patch.dart when trying to use a Navigator widget


Here is my code:

  @override
  Widget build(BuildContext context) {
    final GlobalKey<NavigatorState> navigatorKey1 = GlobalKey<NavigatorState>();
    final GlobalKey<NavigatorState> navigatorKey2 = GlobalKey<NavigatorState>();
    if (!dataReady) {
      return const LoadingScreen();
    } else if (!hasInternet) {
      return const NoInternetScreen();
    } else if (user == null) {
      return const SignupScreen();
    } else if (!user!.emailVerified) {
      return const VerifyEmailScreen();
    } else if (errorOccured) {
      return const ErrorScreen(
          "error code 123");
    } else {
      return Scaffold(
        body: Column(children: [
          Navigator(
            key: navigatorKey1,
            onGenerateRoute: (settings) {
              return MaterialPageRoute(builder: (context) => const HomeScreen());
            },
          ),
          Navigator(
            key: navigatorKey2,
            onGenerateRoute: (settings) {
              return MaterialPageRoute(builder: (context) => const HomeScreen());
            },
          ),
        ]),
        // body: const HomeScreen(),
        bottomSheet: bottomAppBar(context),
      );
    }
  }
}

I'm not too sure what to try or what the problem could be, but I reach an assertion error in the file dart:core-path\errors_patch.dart:

 @pragma("vm:external-name", "AssertionError_throwNew")
  external static _doThrowNew(
      int assertionStart, int assertionEnd, Object? message);

Does anyone have a clue what's wrong with my code?


Solution

  • Maybe it's a size constraints error.
    Try wrapping your Navigator widget inside Expanded Widget, something like Expanded(child: Navigator(