【问题标题】:The following TypeErrorImpl was thrown building Obx, Unexpected null value构建 Obx 时抛出了以下 TypeErrorImpl,意外的 null 值
【发布时间】:2022-10-25 16:25:43
【问题描述】:

当我将 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 一切正常。

提前致谢。

【问题讨论】:

    标签: flutter web controller null flutter-getx


    【解决方案1】:

    您找到解决方案了吗?当我尝试在网络上运行我的应用程序时,我在使用 Riverpod 时遇到了同样的问题。

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 2023-01-21
      • 2023-02-08
      相关资源
      最近更新 更多