英文:
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(
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论