我在尝试使用 Navigator 小部件时,在 errors_patch.dart 中遇到了断言失败错误。

huangapple go评论70阅读模式
英文:

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

问题

这是我的代码:

      @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());
                },
              ),
            ]),
            bottomSheet: bottomAppBar(context),
          );
        }
      }
    }

我不太确定要尝试什么或可能的问题是什么,但我在文件dart:core-path\errors_patch.dart中遇到了断言错误

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


有人知道我的代码有什么问题吗?
英文:

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?

答案1

得分: 1

也许是尺寸限制错误。
尝试将您的Navigator小部件包装在扩展小部件内,类似于Expanded(child: Navigator(

英文:

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

huangapple
  • 本文由 发表于 2023年6月15日 00:15:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定