Reputation: 610
I am working on this Tab Bar for a while, it now looks like this:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
hoverColor: Colors.transparent,
),
title: 'Flutter Demo',
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
leading: Icon(
Icons.menu,
color: Colors.black,
),
actions: [
Icon(
Icons.settings,
color: Colors.black,
),
],
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
title: Padding(
padding: EdgeInsets.only(left: 50, right: 50),
child:TabBar(
indicatorColor: Colors.pink[100],
indicatorSize: TabBarIndicatorSize.label,
tabs: [
Tab(text: 'Dogs'),
Tab(text: 'Cats'),
],
labelColor: Colors.black,
),),
), //appbar
body: TabBarView(
children: [
Center(child: Text('DOGS')),
Center(child: Text('CATS')),
],
),
),
),
);
}
}
It is clear to see that the position of the indicator is not quite right. Ideally, I would like the indicator to vertically move up, closer to (and under) the text("Dogs" && "Cats"), or vertically move down, stay at the bottom of the app bar. How could I achieve that? Any help is appreciated.
Upvotes: 0
Views: 3602
Reputation: 6405
You can controls those things using more parameters of the TabBar
widget.
I have added this,
indicatorWeight: 4,
indicatorPadding: EdgeInsets.symmetric(vertical: 8),
and I got this,
If you want it much closer, play with the vertical
value of indicatorPadding
.
If you want it thicker or thinner, play with the indicatorWeight
.
Upvotes: 3