参数类型'Obx'不能分配给参数类型"首选大小小部件?


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()
],
),
),
),
),

我决定启用或禁用标签栏与boolen值:tabbarenable,但这是不适合我的解决方案,因为每次我不得不运行整个页面只禁用标签栏。

现在我决定使用GetX现在,但当我进入它:Obx( () =>到底部:PreferredSize我得到这个错误'参数类型'Obx'不能分配给参数类型'PreferredSizeWidget?' ' '

帮忙吗?

AppBar接受类型为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);
}

相关内容

最新更新