[英]How do I override a Flutter TabBar Tab to work as a FloatingActionButton?
I'm trying to achieve this functionality:我正在尝试实现此功能:
When I press the last Tab button, I don't want to change to any view.当我按下最后一个 Tab 按钮时,我不想更改为任何视图。 I just want to show those two buttons, no matter which view I'm on.
我只想显示这两个按钮,无论我在哪个视图上。
I've tried with this solution , but it hasn't helped.我试过这个解决方案,但没有用。
class MainViewState extends State<MainView> {
var tabsList = [
Tab1View(),
Tab2View(),
Tab3View(),
Tab4View()
];
@override
Widget build(BuildContext context) {
return ViewModelProvider<MainViewModel>.withConsumer(
viewModel: MainViewModel(),
builder: (context, viewModel, child) => DefaultTabController(
length: tabsList.length,
child: Scaffold(
drawer: mainViewDrawerHeader(context),
appBar: AppBar(
title: Text('Sample Text'),
centerTitle: true,
),
body: TabBarView(children: tabsList),
bottomNavigationBar: TabBar(
labelPadding: EdgeInsets.symmetric(horizontal: 0.0),
labelStyle:
TextStyle(fontSize: 14.5, fontWeight: FontWeight.bold),
unselectedLabelStyle: TextStyle(fontSize: 12.0),
tabs: <Widget>[
Tab(
icon: Icon(Icons.monetization_on),
text: 'Tab 1',
),
Tab(
icon: Icon(Icons.monetization_on),
text: 'Tab 2',
),
Tab(
icon: Icon(Icons.credit_card),
text: 'Tab 3',
),
Tab(
icon: Icon(Icons.phone),
text: 'Tab 4',
),
],
labelColor: Colors.red,
unselectedLabelColor: Colors.grey,
indicatorSize: TabBarIndicatorSize.tab,
indicatorColor: Colors.red,
onTap: (_) => {},
))));
}
}
Yes, one simple way to go about it is to use the Visibility
widget.是的,go 的一种简单方法是使用“
Visibility
”小部件。
Just wrap your column that contains the buttons in a visibility widget.只需将包含可见性小部件中的按钮的列包装起来。
For example例如
bool isClicked = false;
Visibility(
visible: isClicked,
child: Column(
children : [
Icon(Icons.phone),
Icon(Icons.user),
],
)
),
Now in your Fab item do the following:现在在您的 Fab 项目中执行以下操作:
FabItem(
"Contacto",
Icons.phone,
onPress: () {
_controller.reverse();
sisClicked = true;
},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.