参数类型 'Obx' 无法分配给参数类型 'PreferredSizeWidget?

The argument type 'Obx' can't be assigned to the parameter type 'PreferredSizeWidget?

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( () => 到底部:PreferredSize 我收到此错误`参数类型 'Obx' 无法分配给参数类型'PreferredSizeWidget?'``

有什么帮助吗?

Well 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);
}