【问题标题】:The argument type 'Obx' can't be assigned to the parameter type 'PreferredSizeWidget?参数类型“Obx”不能分配给参数类型“PreferredSizeWidget?
【发布时间】:2021-12-13 20:23:00
【问题描述】:
return DefaultTabController(
            length: filteredList.length,
            child: Scaffold(
              appBar: AppBar(
                backgroundColor: (Colors.white),
                iconTheme: const IconThemeData(color: Colors.black),
                title: Transform.translate(
                  offset: const Offset(-24.0, 0.0),
                  child: Image.asset("assets/images/logo.png",
                      fit: BoxFit.contain, height: 22),
                ),
                bottom: PreferredSize(
                  preferredSize: widget.tabbarenable
                      ? const Size.fromHeight(30.00)
                      : const Size.fromHeight(0.00),
                  child: ColoredBox(
                    color: Colors.white,
                    child: Column(
                      children: [
                        widget.tabbarenable
                            ? TabBar(
                                labelColor: Colors.purple[100],
                                indicatorColor: Colors.purple,
                                isScrollable: true,
                                labelPadding:
                                    const EdgeInsets.symmetric(horizontal: 8.0),
                                tabs: tabs)
                            : Container()
                      ],
                    ),
                  ),
                ),
              ),

我决定使用布尔值启用或禁用 Tabbar:tabbarenable 但这不适合我的解决方案,因为每次我必须运行整个页面时只禁用 Tabbar。

现在我决定现在使用 GetX,但是当我输入它时:Obx( () => to bottom: PreferredSize 我收到此错误“无法将参数类型“Obx”分配给参数类型“PreferredSizeWidget?”

有什么帮助吗?

【问题讨论】:

    标签: flutter dart flutter-getx


    【解决方案1】:

    AppBar bottom 接受 PreferredSizeWidget 类型的参数,所以你不能直接用它分配 Obx。因此,您要么必须使用自己的自定义应用栏,要么在小部件内使用Obx,或者使用下面的代码来创建自定义小部件,该小部件通过实现PreferredSizeWidget 为您执行操作。注意:这仍然需要你给它一个preferredSize 来强制。

    class BottomOfAppBar extends StatelessWidget implements PreferredSizeWidget {
      const BottomOfAppBar({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Obx(() => Container());
      }
    
      @override
      Size get preferredSize => Size.fromHeight(55.0);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-23
      • 2021-11-11
      • 1970-01-01
      • 2019-03-11
      • 2021-01-05
      • 2018-12-26
      • 2021-06-19
      • 2021-08-19
      • 2020-06-25
      相关资源
      最近更新 更多