构建 Obx 时抛出以下 TypeErrorImpl,意外的 null 值
当我将 flutter 应用程序作为 Web 应用程序打开时,我目前正在调查以下错误:
The following TypeErrorImpl was thrown building Obx(has builder, dirty, state: _ObxState#4990d):
Unexpected null value.
The relevant error-causing widget was:
Obx Obx:file:///D:/development/flutter/demoapp/lib/root.dart:12:12
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63 nullCheck
packages/demoapp/controllers/authController.dart 13:44 get user
packages/demoapp/root.dart 14:15 <fn>
packages/get/get_state_manager/src/rx_flutter/rx_obx_widget.dart 70:28 build
packages/get/get_rx/src/rx_types/rx_core/rx_interface.dart 26:27 notifyChildren
packages/get/get_state_manager/src/rx_flutter/rx_obx_widget.dart 54:19 build
我的根类:
class Root extends GetWidget<AuthController> {
@override
Widget build(BuildContext context) {
return Obx(() {
return (Get.find<AuthController>().user != null ? LoginPage() : DashboardPage());
});
}
}
我的主类:
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
// initialBinding: AuthBinding(),
initialRoute: RootRoute,
opaqueRoute: true,
unknownRoute: GetPage(name: "/not-found", page: () => PageNotFound(), transition: Transition.noTransition),
defaultTransition: Transition.native,
// transitionDuration: Duration.zero,
getPages: [
GetPage(name: RootRoute, page: () => Root()),
GetPage(name: AuthenticationPageRoute, page: () => LoginPage()),
],
debugShowCheckedModeBanner: false,
title: 'DemoAPP',
theme: ThemeData(
hoverColor: Colors.transparent,
splashColor: Colors.transparent,
// highlightColor: Colors.transparent,
primarySwatch: Colors.blue,
scaffoldBackgroundColor: colorLight,
// scaffoldBackgroundColor: Colors.white,
textTheme: GoogleFonts.mulishTextTheme(
Theme.of(context).textTheme).apply(
bodyColor: Colors.black
),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder()
})
)
);
}
}
有人可以帮助我吗?
当用户登录时不会出现任何问题,用户将直接重定向到 LoginPage Dashboard 页面。另外通过 url /login 一切都很完美。
提前致谢。
I currently investigate the following error, when I open the flutter app as web application:
The following TypeErrorImpl was thrown building Obx(has builder, dirty, state: _ObxState#4990d):
Unexpected null value.
The relevant error-causing widget was:
Obx Obx:file:///D:/development/flutter/demoapp/lib/root.dart:12:12
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63 nullCheck
packages/demoapp/controllers/authController.dart 13:44 get user
packages/demoapp/root.dart 14:15 <fn>
packages/get/get_state_manager/src/rx_flutter/rx_obx_widget.dart 70:28 build
packages/get/get_rx/src/rx_types/rx_core/rx_interface.dart 26:27 notifyChildren
packages/get/get_state_manager/src/rx_flutter/rx_obx_widget.dart 54:19 build
My Root class:
class Root extends GetWidget<AuthController> {
@override
Widget build(BuildContext context) {
return Obx(() {
return (Get.find<AuthController>().user != null ? LoginPage() : DashboardPage());
});
}
}
My Main class:
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
// initialBinding: AuthBinding(),
initialRoute: RootRoute,
opaqueRoute: true,
unknownRoute: GetPage(name: "/not-found", page: () => PageNotFound(), transition: Transition.noTransition),
defaultTransition: Transition.native,
// transitionDuration: Duration.zero,
getPages: [
GetPage(name: RootRoute, page: () => Root()),
GetPage(name: AuthenticationPageRoute, page: () => LoginPage()),
],
debugShowCheckedModeBanner: false,
title: 'DemoAPP',
theme: ThemeData(
hoverColor: Colors.transparent,
splashColor: Colors.transparent,
// highlightColor: Colors.transparent,
primarySwatch: Colors.blue,
scaffoldBackgroundColor: colorLight,
// scaffoldBackgroundColor: Colors.white,
textTheme: GoogleFonts.mulishTextTheme(
Theme.of(context).textTheme).apply(
bodyColor: Colors.black
),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder()
})
)
);
}
}
Can someone help me?
When the user is logged in no problem occurs and the user will be redirected to the LoginPage Dashboard page directly. Also via the url /login everything works perfect.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论