I am trying to create the Tabbar with 3 tabs but the result is not as expected.
Also, In the results white underline below the tabs.
Any help will be appreciated, Thank you!!!
Code:
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
color: Colors.grey[100],
child: Column(
children: [
Expanded(
child: DefaultTabController(
length: 3,
child: Column(
children: [
Material(
child: Padding(
padding: const EdgeInsets.only(left: 18.0, right: 18),
child: Container(
height: 45,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
border: Border.all(
color: const Color.fromARGB(255, 225, 220, 220),
),
color: const Color.fromARGB(255, 225, 222, 222)),
child: TabBar(
physics: const ClampingScrollPhysics(),
padding: const EdgeInsets.all(10),
indicatorSize: TabBarIndicatorSize.label,
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(18),
color: Colors.white,
),
tabs: [
Container(
height: 42,
child: Align(
alignment: Alignment.center,
child: Text(
"11月分",
style: TextStyle(color: Colors.black),
),
),
),
Container(
height: 42,
child: Align(
alignment: Alignment.center,
child: Text(
"12月分",
style: TextStyle(color: Colors.black),
),
),
),
Container(
height: 42,
child: Align(
alignment: Alignment.center,
child: Text(
"1月分",
style: TextStyle(color: Colors.black),
),
),
),
],
),
),
),
),
Expanded(
child: TabBarView(
children: [
Center(child: Text("chat")),
Center(child: Text("messages")),
Center(child: Text("request")),
],
),
)
],
),
),
),
],
),
),
);
}
}
Current result:
Expected output:
2
Answers
This code is to remove the white line in the tab bar
Just wrap it inside the TabBar
Add initstate like this in your code
After that in the Tab bar add controller.
Also add the state with TickerProviderStateMixin like this