[英]Flutter - Hide FAB Button on swipe
我有一个带有TabBarView和FloatingActionButton的脚手架。 每当我滑动到最后一个选项卡时,我都想隐藏此FAB。 为此,我编写了以下代码:
@override
void initState() {
super.initState();
widget._tabBarController = new TabController(length: 3, vsync: this);
widget._tabBarController.addListener(() {
if (widget._tabBarController.index == 2) {
setState(() => widget._visibleFab = false);
} else {
setState(() => widget._visibleFab = true);
}
});
}
带支架的FAB按钮
Visibility(
visible: widget._visibleFab,
child: FloatingActionButton.extended(
elevation: .75,
label: new Text("My Action Button",
style: TextStyle(
fontWeight: FontWeight.w900,
color: statusColor,
letterSpacing: 0.2)),
onPressed: () {
},
backgroundColor: Colors.white,
icon: Icon(Icons.chat, color: statusColor),
isExtended: true,
))
它可以工作,但是当我滑动到最后一个选项卡时,将其隐藏大约需要半秒钟。 除非我不触摸页面而直接触摸最后一个选项卡,否则它将立即被隐藏。
这是为什么?
我最终决定为每个TabBarView
使用一个Scaffold
。 现在,我可以BottomNavigatorBar
为每个选项卡设置一个FloatActionButton
和BottomNavigatorBar
。
如果您不想要Fab,请更改构建方法以返回null。
例如。
floatingActionButton: _createFloatingActionButton(),
Widget _createFloatingActionButton() {
if (!_tfFabVisible) {
return null;
}
return FloatingActionButton(
onPressed: _btnSubmitPressed,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.