Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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;

output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want it to act like Horizontal SingleChildScrollView with BouncingScrollPhysics with full long names. I can’t fix it… Can you help me?

>Solution :

On your TabBar set isScrollable: true,

child: TabBar(
  labelColor: Color(0xffd17842),
  unselectedLabelColor: Color(0xff52555a),
  indicatorColor: Colors.transparent,
  isScrollable: true, // this
  tabs: [
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading