Customize flutter Tab bar - flutter

I am using a TabBar widget and I'd like to customize the TabBar view like this image. I tried lot of times bus there are some spaces between two tabs.
this is the code I used to customize the tab view.
TabBar(
controller: _tabController,
labelColor: Colors.black12,
unselectedLabelColor: Colors.black12,
indicatorSize: TabBarIndicatorSize.label,
tabs: [
Tab(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.horizontal(
left: Radius.circular(50), right: Radius.zero),
border: _tabController.index == 1
? Border.all(color: Colors.black12, width: 2)
: Border.all(color: Colors.transparent, width: 2),
color: _tabController.index == 0
? Colors.indigo
: Colors.white,
),
child: Align(
alignment: Alignment.center,
child: Text("Income"),
),
),
),
Tab(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.horizontal(
left: Radius.zero, right: Radius.circular(50)),
border: _tabController.index == 1
? Border.all(color: Colors.transparent, width: 2)
: Border.all(color: Colors.black12, width: 2),
color: _tabController.index == 1
? Colors.indigo
: Colors.white,
),
child: Align(
alignment: Alignment.center,
child: Text("Expense"),
),
),
),
],
),
output

if you need to customize your tabs,my beautiful tabs source code may be help you,this is not relevent to this post
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class StudentScreen extends StatefulWidget {
#override
_StudentScreenState createState() => _StudentScreenState();
}
class _StudentScreenState extends State<StudentScreen> with SingleTickerProviderStateMixin {
TabController controller;
int activeTabIndex = 1;
#override
void initState() {
super.initState();
controller = TabController(
length: 2,
initialIndex: 1,
vsync: this,
);
controller.addListener(() {
setState(() {
activeTabIndex = controller.index;
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
children: <Widget>[
TabBar(
indicatorColor: Colors.transparent,
tabs: [
Tab(
child: Container(
width: 100,
height: 36,
decoration: activeTabIndex == 0
? BoxDecoration(
border: Border.all(color: Colors.blue, width: 2),
borderRadius: BorderRadius.all(Radius.circular(16)),
)
: null,
child: Padding(
padding: EdgeInsets.fromLTRB(8, 4, 8, 0),
child: Center(child: Text("Tab one", style: TextStyle(color: Colors.black))),
)),
),
Tab(
child: Container(
width: 100,
height: 36,
decoration: activeTabIndex == 1
? BoxDecoration(
border: Border.all(color: Colors.blue, width: 2),
borderRadius: BorderRadius.all(Radius.circular(16)),
)
: null,
child: Padding(
padding: EdgeInsets.fromLTRB(8, 4, 8, 0),
child: Center(child: Text("Tab two", style: TextStyle(color: Colors.black))),
)),
),
],
controller: controller,
),
Container(
child: Row(
children: <Widget>[],
),
),
Expanded(
child: Container(
child: TabBarView(
controller: controller,
children: <Widget>[
Center(child: Text("Tab one")),
Center(child: Text("Tab two")),
],
),
),
)
],
),
),
);
}
}

you can give radius to whole bottom not only the two tabs
you can do something like this
just give radius to all sides I need to give only top right and top left in my case
PreferredSize(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: TabBar(
// indicatorPadding: EdgeInsets.all(30),
tabs: [
Tab(
child: Text(
"Expnanse",
style: TextStyle(color: Colors.black),
),
),
Tab(
child: Text(
"Income",
style: TextStyle(color: Colors.black),
),
),
],
),
),
preferredSize: const Size.fromHeight(70.0),
),
),

You neee to add:
labelPadding: EdgeInsets.all(0),
to your TabBar!

Related

How to customize tabBar?

I want to make tapBar looking like this:
But only got this:
This is my code(DefaultTabContainer is wrapped with container with height: 600 and width: 300):
DefaultTabController(
length: 3,
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(35.h),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10.w),
decoration: BoxDecoration(
//color: const Color(0xFF1C1B20),
borderRadius: BorderRadius.circular(12),
),
child: TabBar(
controller: _tabController,
indicatorPadding:
const EdgeInsets.symmetric(vertical: 5),
indicator: const ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(5)),
),
color: Color(0xFF4F4E51),
),
labelColor: Colors.white,
physics: const NeverScrollableScrollPhysics(),
labelStyle: const TextStyle(
color: Colors.white,
fontSize: 12
),
tabs: const [
Tab(
text: "Day",
),
Tab(
text: "Week",
),
Tab(
text: "Month (Soon)",
),
]),
),
)
)
)
TabController in initState:
_tabController = TabController(vsync: this, length: numberTabs); // numberTabs = 3
I tried to make it like I want but I cannot and I don't understand why...
You can set each tabs as below
tabs:[
Tab(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.red,
),
child: Align(
alignment: Alignment.center,
child: Text(
"Day",
),
),
),
),]

I want to design grid like this in flutter:

I want to design a Grid like the below output in flutter.
Please help with this.
The Code I have tried is this:
Container(
height: 100,
width: 170,
margin: const EdgeInsets.symmetric(horizontal: 30),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.black
),
margin: const EdgeInsets.all(1.5),
child: const Center(
child: Text(
"data",
style: TextStyle(color: Colors.white),
),
),
),
),
),
And the output I get is this:
Thanks in advance for your help.
What you can do to maintain a grid is use Wrap.
Not very efficient for long list of items but for short it will suffice.
Take a look at the code below :
( You can run this code using Dartpad )
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(),
body: Padding(
padding: const EdgeInsets.all(16),
child: LayoutBuilder(builder: (c, box) {
var crossCount = 2;
var spacing = 15.0;
var maxWidth = (box.maxWidth - ((crossCount - 1) * spacing)) / 2;
return Wrap(
spacing: spacing,
runSpacing: spacing,
children: List.generate(
10,
(i) => Stack(
children: [
Container(
width: maxWidth,
height: maxWidth * 0.55 * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(16)),
gradient : LinearGradient(
end: Alignment.topLeft,
begin: Alignment.bottomRight,
colors: [
Colors.black,
Colors.black,
Colors.amber,
],
),
// color: Colors.white,
// boxShadow: [BoxShadow(color: Colors.black, blurRadius: 4)],
),
),
Container(
width: maxWidth,
height: maxWidth * 0.55,
margin: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.black,
),
)
],
),
),
);
}),
),
),
);
}
}
Note : Replace the Container's child with your own UI logic for implementing the design you like.
I tried it by myself and manage to built the same.
This is the Code:
Padding(
padding: const EdgeInsets.all(10),
child: GridTile(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Gate 2",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.white),
),
const Text(
"Unlocked",
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Icon(
Icons.lock,
color: Colors.white,
size: 30,
),
const SizedBox(width: 5),
Image.asset("assets/swipe.png",height: 30,width: 30,),
const SizedBox(width: 5),
// const Icon(Icons.lock, color: Colors.white,size: 30,),
Draggable(
axis: Axis.horizontal,
maxSimultaneousDrags: 3,
rootOverlay: false,
child: Container(
padding: const EdgeInsets.all(5),
decoration: const BoxDecoration(
color: Colors.white12,
borderRadius: BorderRadius.all(Radius.circular(100),),
),
child: const Icon(
Icons.lock_open,
color: Colors.orangeAccent,
size: 30,
),
),
feedback: Container(
decoration: const BoxDecoration(
color: Colors.white12,
borderRadius: BorderRadius.all(Radius.circular(100),),
),
child: const Icon(
Icons.lock_open,
color: Colors.transparent,
size: 40,
),
),
),
],
),
],
),
),
),
Here is the Output.

flutter: how to change tab color?

I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.I want to make change color on tab click.I want to make change color on tab click.I want to make change color on tab click.
this is code
import 'package:cwc/ui/CwcTv/components/slides/slide_component.dart';
import 'package:cwc/ui/CwcTv/components/videos/video_component.dart';
import 'package:cwc/ui/CwcTv/cwc_tv.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/category_page.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class EventTab extends StatefulWidget {
#override
_EventTabState createState() => _EventTabState();
}
class _EventTabState extends State<EventTab> {
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
_tabSection(context),
],
);
}
}
Widget _tabSection(BuildContext context) {
return DefaultTabController(
length: 4,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 10, 14, 0),
child: TabBar(
isScrollable: true,
labelColor: Colors.black,
indicatorColor: Colors.white,
tabs: [
Tab(
child: Container(
width: 66,
height: 32,
decoration: const BoxDecoration(
color: Color(0xff158998),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'All',
style: GoogleFonts.poppins(
color: Color(0xffffffff),
fontSize: 12,
),
),
),
),
),
Tab(
child: Container(
width: 85,
height: 32,
decoration: const BoxDecoration(
color: Color(0xffF1F2F6),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'Category',
style: GoogleFonts.poppins(
color: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
Tab(
child: Container(
width: 85,
height: 32,
decoration: const BoxDecoration(
color: Color(0xffF1F2F6),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'Upcoming',
style: GoogleFonts.poppins(
color: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
Tab(
child: Container(
width: 66,
height: 32,
decoration: const BoxDecoration(
color: Color(0xffF1F2F6),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'Free',
style: GoogleFonts.poppins(
color: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * (50 / 100),
child: const TabBarView(
children: [
Activities(),
CategoryPage(),
Activities(),
Activities(),
],
),
),
],
),
),
),
);
}
this time I have clicked on category page but I want to change color
Please Refer Below Code:-
import 'package:cwc/ui/CwcTv/components/slides/slide_component.dart';
import 'package:cwc/ui/CwcTv/components/videos/video_component.dart';
import 'package:cwc/ui/CwcTv/cwc_tv.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/category_page.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class EventTab extends StatefulWidget {
#override
_EventTabState createState() => _EventTabState();
}
class _EventTabState extends State<EventTab>
with SingleTickerProviderStateMixin, WidgetsBindingObserver {
TabController controller;
#override
void initState() {
// TODO: implement initState
super.initState();
controller = TabController(length: 4, vsync: this);
controller.addListener(_handleTabSelection);
WidgetsBinding.instance.addObserver(this);
}
#override
void dispose() {
// TODO: implement dispose
super.dispose();
WidgetsBinding.instance.removeObserver(this);
controller?.dispose();
}
void _handleTabSelection() {
setState(() {});
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
_tabSection(context, controller),
],
);
}
}
Widget _tabSection(BuildContext context, TabController controller) {
return DefaultTabController(
length: 4,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 10, 14, 0),
child: TabBar(
controller: controller,
unselectedLabelColor: Colors.grey,
indicatorColor: Colors.white,
isScrollable: true,
tabs: [
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 66,
height: 32,
color: controller.index == 0
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'All',
style: GoogleFonts.poppins(
color: controller.index == 0
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 85,
height: 32,
color: controller.index == 1
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Category',
style: GoogleFonts.poppins(
color: controller.index == 1
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 85,
height: 32,
color: controller.index == 2
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Upcoming',
style: GoogleFonts.poppins(
color: controller.index == 2
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 66,
height: 32,
color: controller.index == 3
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Free',
style: GoogleFonts.poppins(
color: controller.index == 3
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * (50 / 100),
child: const TabBarView(
children: [
Activities(),
CategoryPage(),
Activities(),
Activities(),
],
),
),
],
),
),
),
);
}

How to create a DraggableScrollableSheet with showModelBottomSheet?

I created with showModelBottomSheet with DraggableScrollableSheet(), But the problem is the there is no appBar for show some text while dragging, ie, the SingleChildsSrollView() will move up and down while dragging.
*bottomsheet(context) {
Size size = MediaQuery.of(context).size;
return showModalBottomSheet(
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(13)),
),
context: context,
builder: (BuildContext context) {
return Padding(
padding: const EdgeInsets.all(5),
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
foregroundColor: Colors.green,
backgroundColor: Colors.white,
elevation: 1,
shadowColor: Colors.grey.shade100,
automaticallyImplyLeading: false,
title: const Text('Connect with Reconnect'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(
25,
),
child: Container(
padding: const EdgeInsets.only(
left: 15,
right: 15,
top: 15,
),
height: size.height,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13),
boxShadow: const [
BoxShadow(blurRadius: 2, color: Colors.grey),
],
),
child: Column(children: [
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(
label: const Text('Name'),
labelStyle: TextStyle(color: Colors.grey.shade500),
icon: const Icon(
FontAwesomeIcons.user,
color: Color(0xff453e3d),
size: 22,
),
border: InputBorder.none,
),
),
Container(
width: 315,
height: 1,
margin: const EdgeInsets.only(top: 3, bottom: 3),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(
label: const Text('Email'),
labelStyle: TextStyle(color: Colors.grey.shade500),
icon: const Icon(
FontAwesomeIcons.envelope,
color: Color(0xff453e3d),
size: 22,
),
border: InputBorder.none,
),
),
Container(
width: 315,
height: 1,
margin: const EdgeInsets.only(top: 3, bottom: 3),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(
label: const Text('Phone Number'),
labelStyle: TextStyle(color: Colors.grey.shade500),
icon: const Icon(
FontAwesomeIcons.mobileAlt,
color: Color(0xff453e3d),
size: 22,
),
border: InputBorder.none,
),
),
Container(
width: 315,
height: 1,
margin: const EdgeInsets.only(top: 3, bottom: 3),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
margin: const EdgeInsets.only(top: 10),
height: 25,
alignment: Alignment.bottomLeft,
child: Row(
children: [
const Icon(
FontAwesomeIcons.car,
color: Color(0xff453e3d),
),
const SizedBox(
width: 15,
),
Text(
'Services',
style: TextStyle(
color: Colors.grey.shade500, fontSize: 16),
),
],
),
),
]),
),
),
),
),
);
});
}*
I need a bar on top of the singlechildscrollview, I tried with column instead, but no result.
The Problem will solve by the following code!
body: Center(
child: Column(
children: [
const SizedBox(
height: 400,
),
ElevatedButton(
onPressed: () =>
//The showModelBottomSheet Will push a sheet to our page for show widgets and actions
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) =>
//The DraggableScrollableSeet will drag top to bottom or vise versa with respect to user interaction.
DraggableScrollableSheet(
initialChildSize: .6,
maxChildSize: .9,
minChildSize: .2,
builder: (context, controller) =>
//The customsheet method will return a widget with a child CustoomScrollView to Drag our DraggableScrollableSheet.
customSheet(context, controller),
),
),
child: const Text('clickme'),
),
],
),
),
//customSheet body
Widget customSheet(BuildContext context, ScrollController controller) {
return Container(
alignment: Alignment.bottomLeft,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
// While use the CustomScrollView have an SliverAppBar for set our bar to constant, ie, the appBar will not move while dragging
child: CustomScrollView(
controller: controller,
slivers: [
SliverAppBar(
shadowColor: Colors.grey.shade100,
elevation: 1,
pinned: true,
backgroundColor: Colors.white,
automaticallyImplyLeading: false,
title: Container(
margin: const EdgeInsets.only(bottom: 45),
width: 60,
height: 4,
color: Colors.grey.shade300),
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.grey.shade200),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
),
SliverFillRemaining(
hasScrollBody: false,
child: Column(
children: [
for (int i = 0; i < 10; i++)
Container(
width: 100,
height: 100,
color: Colors.green[i * 100],
),
],
),
)
],
),
);
}
Problem: The above code has a problem with an exit from the DraggableScrollableSheet(),
this is because if we use a GestureDetecter instead of DraggableScrollableSheet(), the child will pop by the following code
GestureDetector(onTap: ()=>Navigator.of(context).pop(),behavior: HitTestBehavior.opaque,
child: DraggableScrollableSheet(
initialChildSize: .6,
maxChildSize: .9,
minChildSize: .2,
builder: (context, controller) =>
customSheet(context, controller),
),
),
But we cannot pop the sheet with tapped by outside of the DraggableScrollabelSheet().
Note: the HitTestBehaviour.opaque will pop the sheet but if we tap anywhere in the Scaffold.
Thank You for following me up and If you have the solution, Please ping me #sureshm2suresh#gmail.com

Add vertical line as a divider in tabbar as a divider

I have a tab bar and i need to put a vertical line as a divider between tabs, how to do that?
this how i used my tabbar:
new TabBar(
unselectedLabelColor: Color.fromRGBO(119, 119, 119, 1),
labelColor: Colors.black,
controller: controller,
tabs: <Tab>[
new Tab(text: "Girls"),
new Tab(text: "Hero"),
new Tab(text: "Open"),
]),
and I need it to be like this:
Finally It worked for me
TabBar(
tabs: [
_individualTab('assets/icons/bottom_nav/Home.png'),
_individualTab('assets/icons/bottom_nav/Guys.png'),
_individualTab('assets/icons/bottom_nav/Notes.png'),
Tab(
icon: ImageIcon(
AssetImage('assets/icons/bottom_nav/Email.png')
),
),
],
labelColor: STColors.PRIMARY_COLOR,
unselectedLabelColor: Colors.grey,
indicatorColor: Colors.white,
indicatorSize: TabBarIndicatorSize.tab,
labelPadding: EdgeInsets.all(0),
indicatorPadding: EdgeInsets.all(0),
),
Individual Tab Function
Widget _individualTab(String imagePath) {
return Container(
height: 50 + MediaQuery
.of(context)
.padding
.bottom,
padding: EdgeInsets.all(0),
width: double.infinity,
decoration: BoxDecoration(border: Border(right: BorderSide(color: STColors.LIGHT_BORDER, width: 1, style: BorderStyle.solid))),
child: Tab(
icon: ImageIcon(AssetImage(imagePath)),
),
);
}
To achieve small size separator you can use this.
Widget _individualTab(String imagePath) {
return Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
border: Border(right: BorderSide(color: STColors.LIGHT_BORDER,
width: 0,
style: BorderStyle.solid),
),
),
child: Stack(children: <Widget>[
Center(
child: Tab(
icon: ImageIcon(AssetImage(imagePath)),
),
),
Align(
alignment: Alignment.centerRight,
child: Container(
color: STColors.appBlackMedium,
width: 1,
height: 25,
),
)
],)
);
}
All you need is
indicator: BoxDecoration(
border: Border(
left: BorderSide(color: Colors.grey), // provides to left side
right: BorderSide(color: Colors.grey), // for right side
),
),
Your solution:
new TabBar(
indicator: BoxDecoration(border: Border(right: BorderSide(color: Colors.orange))),
unselectedLabelColor: Color.fromRGBO(119, 119, 119, 1),
labelColor: Colors.black,
controller: controller,
tabs: <Tab>[
new Tab(text: "Girls"),
new Tab(text: "Hero"),
new Tab(text: "Open"),
]),
Here is the Header I want to achieve
Yea, so I added a var called rightDivider which lets you render divider but the last tab on my custom tab widget.
import 'package:flutter/material.dart';
class TabWidget extends StatelessWidget {
final String label;
final bool rightDivider;
TabWidget({
required this.label,
required this.rightDivider,
});
#override
Widget build(BuildContext context) {
return Container(
height: 32 + MediaQuery.of(context).padding.bottom,
width: double.infinity,
padding: EdgeInsets.all(0),
decoration: (rightDivider)
? BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.grey,
width: 1,
style: BorderStyle.solid,
),
),
)
: null,
child: Center(child: Text(label)),
);
}
}
And called this widget like this
TabBar(
controller: _tabController,
tabs: [
TabWidget(
label: 'Today',
rightDivider: true,
),
TabWidget(
label: 'Calendar',
rightDivider: true,
),
TabWidget(
label: 'Report',
rightDivider: false,
),
],
)
That's how I achieve this behavior...
HomeTab({required String title, bool isSeprator = true}) {
return Tab(
child: Container(
width: 100,
height: 20,
child: Center(
child: Text(title),
),
decoration: isSeprator
? BoxDecoration(
border: Border(
left: BorderSide(
color: Colors.grey,
width: 1,
style: BorderStyle.solid,
),
),
)
: null,
),
);
}
isSeparator is to show separator or not ... because on the last index I am not showing...
Following is the list of tabs ...
List<Widget> _tabScroll() => [
HomeTab(title: "Tab1"),
HomeTab(title: "Tab2"),
HomeTab(title: "Tab3", isSeparator: false),
];
and following is the most important TabBar Code...
TabBar(
labelPadding: EdgeInsets.symmetric(horizontal: 0), //removing extra space
controller: _controller,
isScrollable: true,
indicatorColor: Colors.black,
indicatorSize: TabBarIndicatorSize.label,
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 3.0), //hight of indicator
insets: EdgeInsets.symmetric(horizontal: 30.0), //give some padding to reduce the size of indicator
),
unselectedLabelColor: Colors.grey,
tabs: _tabScroll(), //list of tabs
),
The end result looks like this...
Working solution is to create border for individual tabs. Tabs parameter actually accept other elements as a child. So you can use custom containers. That way you can control which side border you want to show (left, rigth or any side):
TabBar(
controller: _tabController,
indicator: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.red,
offset: Offset(0, 2.0),
)
],
color: Colors.white,
),
labelColor: Colors.red,
unselectedLabelColor: Colors.grey.shade900,
labelPadding: EdgeInsets.symmetric(horizontal: 1.0),
isScrollable: false,
tabs: [
Container(
child: Center(
child: Text('T1'),
),
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.grey,
width: 2,
style: BorderStyle.solid,
),
),
)),
Container(
child: Center(
child: Text('T2'),
),
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.grey,
width: 2,
style: BorderStyle.solid,
),
),
)),
Container(
child: Center(
child: Text('T3'),
),
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.grey,
width: 2,
style: BorderStyle.solid,
),
),
)),
Tab(
text: 'T4',
),
],
),
Thats how i have done this
I am using screenutils package from pub you can also use it
SizedBox(
width: 342.w,
height: 41.h,
child: Material(
color: const Color(0xffE2E2E2),
borderRadius: BorderRadius.circular(5),
child: Padding(
padding: EdgeInsets.all(2),
child: TabBar(
padding: EdgeInsets.zero,
indicatorPadding: EdgeInsets.zero,
labelPadding: EdgeInsets.zero,
indicator: BoxDecoration(
color: Color(0xffFFFFFF),
// borderRadius: BorderRadius.circular(5.0)
),
labelColor: Colors.black,
unselectedLabelColor: Color(0xff999BA2),
tabs: [
Container(
width: 1.sw,
decoration: BoxDecoration(
// color: Colors.black,
border: Border(right: BorderSide(color: Colors.white))
),
child: Tab(
text: 'Call',
),
),
Container(
width: 1.sw,
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.white))
),
child: Tab(
text: 'Missed Call',
),
// child: Tab(text: 'Phone',),
),
Container(
child: Tab(
text: 'No Call',
),
// child: Tab(text: 'No Call'),
),
],
),
),
),
)
enter image description here