I need to implement tab like this: https://i.stack.imgur.com/12iVI.png
I have done tabBar Using this Code I am not getting transparent background as like in the attached picture
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),
],
),
),
],
);
Here its my code for tab
So, what you actually want is the behavior of a Stack
, not the behavior of a Column
since you want to TabBar
to be in front of your content and not above.
Means simply changing the Column
to a Stack
and pushing the TabBar
at the end of the children
Array for bringing it to the front should be the trick.
Here is the code I suggest:
@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",),
)
],
),
),
],
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.