How to modify the default top navigation bar style in flutter - flutter

I want to make a top navigation bar with this effect, but it's very difficult to modify the default tab style of tabcontroller! Then I try to use container to modify it by myself. It's very simple, but the problem is that I can't support left and right swiping to switch pages. Because the gesture has been blocked by pageview. So in the end, I think it's better to use the tab provided by the system and then modify the style, some one help me!
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
],
),
),
),
);

The indicator property of TabBar can be used to achieve the look.
In your case, try this-
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: Container(
color: Colors.grey[200],
width: 200,
child:TabBar(
labelColor: Colors.red,
unselectedLabelColor: Colors.grey,
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white),
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
],
),
),
),
);

my code is here
DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: PreferredSize(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(0xfff0f4f7)),
width: 193,
height: 36,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: TabBar(
labelColor: ThemeColor,
unselectedLabelColor: MainTextColor,
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.white),
labelPadding: EdgeInsets.all(0),
indicatorSize: TabBarIndicatorSize.label,
tabs: [
Tab(
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
width: 95,
child: Text(
"transfer_upload_list".tr,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w600),
)),
)),
Tab(
child: Container(
width: 95,
child: Text(
"transfer_download_list".tr,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w600),
),
)),
]),
)),
preferredSize: Size(193, 36),
)),
));

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",
),
),
),
),]

When I scroll the list, the tab bar "vibrate"

I have a TabBar in the AppBar and a ListView in the TabBarView. When I scroll the list, the TabBar "vibrate". If you notice at the gif below, there actually appears a little white space at the bottom of AppBar, below the tabs. This space appears and disappears so fast that it gives an impression of vibration. I want the TabBar to be at the bottom of the AppBar with no space below the TabBar.
The code of AppBar:
_appBar(){
return PreferredSize(
preferredSize: Size.fromHeight(160),
child: AppBar(
toolbarHeight: 70,
backgroundColor: Colors.white,
shadowColor: Colors.black,
elevation: 7,
centerTitle: true,
bottom: PreferredSize(
preferredSize: Size.fromHeight(90.0),
child: Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Column(
children: [
Container(
height: 40,
width: MediaQuery.of(context).size.width - 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Color.fromRGBO(243, 243, 243, 1),
),
child: Center(
child: Form(
child: TextFormField(
controller: searchController,
autocorrect: false,
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
contentPadding: EdgeInsets.only(right: 1, left: 14, top: 14, bottom: 14),
label: Text("Nome, nº de série"),
labelStyle: TextStyle(
fontFamily: "OpenSans",
fontSize: 16,
color: Color.fromRGBO(60, 60, 67, 0.6)
),
prefixIcon: Icon(Icons.search),
border: InputBorder.none,
floatingLabelBehavior: FloatingLabelBehavior.never,
),
),
),
),
),
SizedBox(height: 15),
TabBar(
controller: _tabController,
labelPadding: EdgeInsets.only(left: 5, right: 5),
indicatorColor: Theme.of(context).primaryColor,
indicatorSize: TabBarIndicatorSize.label,
indicatorWeight: 3.0,
labelColor: Colors.black,
labelStyle: TextStyle(
fontSize: 16,
fontFamily: "OpenSans"
),
tabs: const [
Tab(text: "RASCUNHOS"),
Tab(text: "EM PROCESSO"),
Tab(text: "FINALIZADO"),
]
)
],
),
),
),
),
);
}
I already removed the TabBar indicator decorations and the problem still happens.

Remove Side Portion from DefaultTabController in Flutter

I am using DefaultTabController widget in Flutter and the output is as below :
I want to remove left and right white background portion as you can see it in above image.
How can I remove that portion or can change the color to dark ?
So far I am trying it as below :
return ThemeData(
tabBarTheme: const TabBarTheme(
),
);
Now, here I am not able to find property that changes the white color to dark color. Please guide. Thanks.
Code :
return DefaultTabController(
length: 3,
child: Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
appBar: AppBar(
titleSpacing: 24.w,
centerTitle: false,
title: Text(
Localization.of(context).labelFacilities,
style: TextStyle(
fontWeight: FontWeight.w600,
color: getBool(isDarkMode) ? whiteColor : textColorBlack,
fontSize: 20.sp),
),
actions: <Widget>[
Container(
margin: EdgeInsets.only(right: 28.w),
child: Image.asset(icSearch,
width: 18.w,
height: 18.h,
color: getBool(isDarkMode) ? whiteColor : textColorBlack),
)
],
backgroundColor: Theme.of(context).backgroundColor,
elevation: 0,
bottom: PreferredSize(
preferredSize: _tabBar.preferredSize,
child: Material(
borderRadius: BorderRadius.circular(10.w), //<-- SEE HERE
child: Container(
child: _tabBar,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: lightYellowColor,
borderRadius: BorderRadius.circular(10.w)),
margin: EdgeInsets.symmetric(horizontal: 24.w),
),
),
),
),
body: Container(
margin: EdgeInsets.only(top: 24.h, right: 24.w, left: 24.w),
child: TabBarView(
children: [
AttractionsScreen(),
EventsScreen(),
UtilitiesScreen(),
],
),
),
));
Tabbar widget is created as below :
TabBar get _tabBar => TabBar(
labelPadding: EdgeInsets.zero,
indicatorWeight: 1,
padding: EdgeInsets.zero,
indicatorPadding: EdgeInsets.zero,
labelStyle: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14.h,
fontFamily: 'Poppins',
),
//For Selected tab
unselectedLabelStyle: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14.h,
fontFamily: 'Poppins',
),
labelColor: Colors.white,
unselectedLabelColor: textColorBlack,
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(10.w), color: yellowColor),
tabs: [
Tab(
child: Align(
alignment: Alignment.center,
child: Text(Localization.of(context).labelAttractions),
),
),
Tab(
child: Align(
alignment: Alignment.center,
child: Text(Localization.of(context).labelEvents),
),
),
Tab(
child: Align(
alignment: Alignment.center,
child: Text(Localization.of(context).labelUtilities),
),
),
]);
You can find some padding properties on TabBar and set it zero.
TabBar(
padding: EdgeInsets.zero,
labelPadding: EdgeInsets.zero,
indicatorPadding: EdgeInsets.zero,
tabs: [....],
),
#1 You can add color in
Material(
color: "YOUR_COLOR",
)
#2 Remove that portion
Code:
PreferredSize(
preferredSize: _tabBar.preferredSize,
child: Material(
color: lightYellowColor, // <-- Change color HERE
borderRadius: BorderRadius.circular(10.w), //<-- SEE HERE
child: Container(
child: _tabBar,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: lightYellowColor,
borderRadius: BorderRadius.circular(10.w)),
margin: EdgeInsets.symmetric(horizontal: 24.w), //<--Remove that portion
),
),
),

Flutter - Tab Names Are Not Fitting In TabBar

I'm trying to add TabBar in my Flutter application. I will use 5 tabs with long names. For now, I added them like this;
DefaultTabController(
length: 5, // length of tabs
initialIndex: 0,
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[
Container(
child: TabBar(
labelColor: Color(0xffd17842),
unselectedLabelColor: Color(0xff52555a),
indicator: DotIndicator(
color: Color(0xffd17842),
distanceFromCenter: 16,
radius: 3,
paintingStyle: PaintingStyle.fill,
),
indicatorColor: Colors.transparent,
tabs: [
Tab(text: 'Cappuccino'),
Tab(text: 'Espresso'),
Tab(text: 'Latte'),
Tab(text: 'Espresso'),
Tab(text: 'Cappuccino'),
],
),
),
Container(
height: 250, //height of TabBarView
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.grey, width: 0.5))
),
child: TabBarView(children: <Widget>[
Container(
child: Center(
child: Text('Display Tab 1', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 2', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 3', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 4', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 5', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
])
)
])
)
But the output is this;
I want it to act like Horizontal SingleChildScrollView with BouncingScrollPhysics with full long names. I can't fix it... Can you help me?
On your TabBar set isScrollable: true,
child: TabBar(
labelColor: Color(0xffd17842),
unselectedLabelColor: Color(0xff52555a),
indicatorColor: Colors.transparent,
isScrollable: true, // this
tabs: [
set isScrollable property to true
isScrollable: true
I solved the problem by reducing the space between tabs.
enter image description here

Flutter I'm trying to add a tabbarview to my app, but nothing works, I want a tab to show cases from Brazil and another from the world

I tried to use NestedScrollView but was unsuccessful, I don't know where I can put the tabbarview how can I use tabbarview in this code
my app looks like this:
SliverToBoxAdapter _buildRegionTabBar() { //brasil e mundo
return SliverToBoxAdapter(
child: DefaultTabController(
length: 2,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 20.0),
height: 50.0,
decoration: BoxDecoration(
color: Colors.white24,
borderRadius: BorderRadius.circular(25.0),
),
child: TabBar(
indicator: BubbleTabIndicator(
tabBarIndicatorSize: TabBarIndicatorSize.tab,
indicatorHeight: 40.0,
indicatorColor: Colors.white,
),
labelStyle: Styles.tabTextStyle,
labelColor: Colors.black,
unselectedLabelColor: Colors.white,
tabs: <Widget>[
Tab (text:'Brasil'),
Tab (text:'Mundo'),
],
onTap: (index) {},
),
),
),
);
}
}
You're missing TabBarView.
This is how it should be done. Modify this code to achieve your result:
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.flight)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_car)),
],
),
title: Text('Tabs Demo'),
),
body: TabBarView(
children: [
Icon(Icons.flight, size: 350),
Icon(Icons.directions_transit, size: 350),
Icon(Icons.directions_car, size: 350),
],
),
),
);
For more info you can refer here : https://blog.logrocket.com/flutter-tabbar-a-complete-tutorial-with-examples/