flutter - PreferredSize 和 GetX 的使用
问题描述
我的 AppBar 具有 git 底部属性和执行类,但在此类中BottomOfAppBar
忽略了颤振。preferredSize
如果 TabBar 被禁用,我的目标是让 AppBar 的高度设置为 0px。(tabbarenable2 值是自己的主要目标,但我找不到动态设置 AppBar 高度的方法)
这是代码:
class BottomOfAppBar extends StatelessWidget with PreferredSizeWidget {
final TabBarController controller;
BottomOfAppBar({Key? key, required this.tabs, required this.controller})
: super(key: key);
final List<Widget> tabs;
final tabbarenable2 = Get.find<RxBool>(tag: 'tabbarenable');
@override
Widget build(BuildContext context) {
return Obx(
() => PreferredSize(
preferredSize: tabbarenable2.value
? const Size.fromHeight(28.0)
: const Size.fromHeight(0.0),
child: ColoredBox(
color: Colors.white,
child: Column(
children: [
tabbarenable2.value
? TabBar(
labelColor: Colors.purple[100],
indicatorColor: Colors.purple,
isScrollable: true,
labelPadding: const EdgeInsets.only(left: 8.0),
tabs: tabs)
: const Text('noTabBar')
],
),
),
),
);
}
@override
Size get preferredSize =>
tabbarenable2.value ? Size.fromHeight(28.0) : Size.fromHeight(0.0);
}
有什么帮助吗?
第一次启动一切似乎都很好:
导航到视频 ( tabbarenable
= false)
它只是更正自己首先刷新页面(正确的tabBar高度)
解决方案
好的,只需尝试以下代码段,如果它不起作用,请让我看看用法
- 我在这里所做的尝试是在显示小部件之前进行检查,也许正确的位置将在“bottomAppBar:[检查这里]”
注意不要检查 build 方法中的布尔值,因为这是一遍又一遍地重建小部件的坏方法。
class BottomOfAppBar extends StatelessWidget with PreferredSizeWidget { final TabBarController controller; BottomOfAppBar({Key? key, required this.tabs, required this.controller}) : super(key: key); final List<Widget> tabs; final tabbarenable2 = Get.find<RxBool>(tag: 'tabbarenable'); @override Widget build(BuildContext context) { return Obx( () => !tabbarenable2.value ? SizedBox() : PreferredSize( preferredSize: const Size.fromHeight(28.0), child: ColoredBox( color: Colors.white, child: Column( children: [ TabBar( labelColor: Colors.purple[100], indicatorColor: Colors.purple, isScrollable: true, labelPadding: const EdgeInsets.only(left: 8.0), tabs: tabs) ], ), ), ), ); } @override Size get preferredSize => tabbarenable2.value ? Size.fromHeight(28.0) : Size.fromHeight(0.0); }
推荐阅读
- python - 排除名称中带有空格的整个目录
- javascript - 当同一行中的另一个单元格在 Javascript 中具有值时,验证一个单元格是否成为必需的
- excel - 拆分数据并使用 vba 进行比较
- python - 用奇怪的 html 抓取网站
- c# - 有效的 RegEx 不适用于 ASP.Net MVC 正则表达式属性
- mips - 谁能告诉我在这个 MIPS 代码中犯了什么错误?
- python - 导入错误:libopencv_hdf.so.3.3
- c++ - 三角形,C++ 构造,计算角度的问题
- java - 字段或构造函数或两者上的休眠验证注释?
- internationalization - i18next 语言检测和与 hapi 集成的问题