【问题标题】:Getx() and hide bottomnavigation bar - error with stateful widget renderingGetx() 并隐藏底部导航栏 - 有状态小部件呈现错误
【发布时间】:2021-09-05 10:22:05
【问题描述】:

我的无状态小部件中有一个有状态小部件 (miniplayer)。我试图隐藏底部导航栏并在使用 Obx 时收到以下错误...知道如何解决这个问题吗?

I/flutter (9567):══╡ 小部件库╞═══════════════════════════ ════════════════════════════ I/flutter(9567):在构建 ValueListenableBuilder(脏,依赖项: 我/颤振(9567):[_LocalizationsScope-[GlobalKey#87424],_InheritedTheme],状态: 我/颤振(9567):_ValueListenableBuilderState#23ae3): I/flutter (9567):在构建期间调用 setState() 或 markNeedsBuild()。 I/flutter (9567):这个 Obx 小部件不能被标记为需要构建,因为框架已经在进程中 I/flutter(9567):构建小部件。只有在以下情况下,小部件才能在构建阶段标记为需要构建 I/flutter (9567):它的一个祖先正在建造中。允许此异常,因为框架构建 I/flutter (9567):父控件在子控件之前,这意味着将始终构建脏后代。否则,该 I/flutter (9567):框架在这个构建阶段可能不会访问这个小部件。 I/flutter (9567):调用 setState() 或 markNeedsBuild() 的小部件是: 我/颤动(9567):Obx I/flutter ( 9567): 发出违规调用时当前正在构建的小部件是: 我/颤振(9567):ValueListenableBuilder 我/颤动(9567): I/flutter(9567):相关的导致错误的小部件是: 我/颤振(9567):迷你播放器

底部导航代码

 bottomNavigationBar: Container(
          child: Obx(
            () => !_videoController.showBottomNavigation.value
                ? SizedBox.shrink()
                : BottomNavigationBar(
                    currentIndex: 0,
                    fixedColor: Colors.blue,
                    items: [
                      BottomNavigationBarItem(
                        icon: Icon(Icons.home),
                        label: 'Home',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(Icons.mail),
                        label: 'Messages',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(Icons.person),
                        label: 'Profile',
                      )
                    ],
                  ),
          ),

【问题讨论】:

    标签: flutter flutter-getx


    【解决方案1】:

    尝试用 isTrueisFalse 声明布尔条件。然后包装 UI 更改。

    bottomNavigationBar: Container(
              child: Obx(
                (){ return _videoController.showBottomNavigation.isFalse
                    ? SizedBox.shrink()
                    : BottomNavigationBar(
                        currentIndex: 0,
                        fixedColor: Colors.blue,
                        items: [
                          BottomNavigationBarItem(
                            icon: Icon(Icons.home),
                            label: 'Home',
                          ),
                          BottomNavigationBarItem(
                            icon: Icon(Icons.mail),
                            label: 'Messages',
                          ),
                          BottomNavigationBarItem(
                            icon: Icon(Icons.person),
                            label: 'Profile',
                          )
                        ],
                      ),
              }),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      相关资源
      最近更新 更多