gpt4 book ai didi

flutter - 在tab中重叠tabbarview与选项卡

转载 作者:行者123 更新时间:2023-12-03 04:40:36 25 4
gpt4 key购买 nike

我需要实现这样的选项卡:/image/12iVI.png
我已经完成了tabBar使用此代码,我没有像所附图片中那样获得透明背景

     Column(
children: <Widget>[
Material(
color: Colors.transparent,
child: TabBar(
indicatorSize: TabBarIndicatorSize.label,
unselectedLabelColor: Colors.black,
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 2.0, color: Color(0xffD65A32)),
insets: EdgeInsets.symmetric(horizontal: 10.0)),
isScrollable: true,
controller: _tabController,
tabs: [
Tab(
child: Text("Maps", style: tabStyle),
),
Tab(
child: Text("Sections", style: tabStyle),
),
Tab(
child: Text("Events", style: tabStyle),
),
Tab(
child: Text("Gallery", style: tabStyle),
),
Tab(
child: Text("Archives", style: tabStyle),
)
],
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: [
MyHomePage(),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
],
);
这是我的选项卡代码

最佳答案

因此,您真正想要的是Stack的行为,而不是Column的行为,因为您希望TabBar位于内容的前面而不是上方。
只是简单地将Column更改为Stack并将TabBar推到children数组的末尾以将其带到前面应该是技巧。
这是我建议的代码:

  @override
Widget build(BuildContext context) {

TabController controller = TabController(
initialIndex: 0,
length: 5,
vsync: this
);

return Stack(
alignment: Alignment.topCenter,
children: <Widget>[
TabBarView(
controller: controller,
children: [
Container(color: Colors.red),
Container(color: Colors.blue),
Container(color: Colors.yellow),
Container(color: Colors.green),
Container(color: Colors.purple),
],
),
Material(
color: Colors.transparent,
child: TabBar(
indicatorSize: TabBarIndicatorSize.label,
unselectedLabelColor: Colors.black,
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 2.0, color: Color(0xffD65A32)),
insets: EdgeInsets.symmetric(horizontal: 10.0)),
isScrollable: true,
controller: controller,
tabs: [
Tab(
child: Text("Maps",),
),
Tab(
child: Text("Sections",),
),
Tab(
child: Text("Events",),
),
Tab(
child: Text("Gallery",),
),
Tab(
child: Text("Archives",),
)
],
),
),
],
);
}

关于flutter - 在tab中重叠tabbarview与选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63334831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com