Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter TabBar Margin/padding between label

Tags:

flutter

dart

I have 3 TabBars and I want to place the label to the left of the categories.

The TabBar I want:

enter image description here

My TabBar:

enter image description here

My code:

       // BOTTOM
      bottom: PreferredSize(
        preferredSize: const Size.fromHeight(kToolbarHeight),
        child: Align(
          alignment: Alignment.centerLeft,
          child: Container(
            width: MediaQuery.of(context).size.width / 1.1,
            child: TabBar(
              labelPadding: EdgeInsets.all(0),
              labelColor: Colors.white,
              labelStyle: poppins.copyWith(
                fontSize: 15,
                fontWeight: bold,
              ),
              unselectedLabelColor: Color(0xff585861),
              indicatorColor: Colors.white,
              indicatorSize: TabBarIndicatorSize.label,

              // TABS
              tabs: [
                Tab(
                  text: 'Following',
                ),
                Tab(
                  text: 'Trending',
                ),
                Tab(
                  text: 'Search',
                ),
              ],
            ),
          ),
        ),
      ),
like image 783
CCP Avatar asked Jul 14 '26 23:07

CCP


2 Answers

Refer below code and try to add isScrollable: true, inside TabBar() widget

Refer Tabbar here

Refer isScrollable here

   bottom: PreferredSize(
        preferredSize: const Size.fromHeight(kToolbarHeight),
        child: Align(
          alignment: Alignment.centerLeft,
          child: Container(
            width: MediaQuery.of(context).size.width / 1.1,
            child: TabBar(
              labelPadding: EdgeInsets.all(5),
              labelColor: Colors.white,
              isScrollable: true,// add this property
              unselectedLabelColor: Color(0xff585861),
              indicatorColor: Colors.white,
              indicatorSize: TabBarIndicatorSize.label,

              // TABS
              tabs: [
                Tab(
                  text: 'Following',
                ),
                Tab(
                  text: 'Trending',
                ),
                Tab(
                  text: 'Search',
                ),
              ],
            ),
          ),
        ),
      ),

Your result screen-> image

like image 120
Ravindra S. Patil Avatar answered Jul 17 '26 14:07

Ravindra S. Patil


Just use the labelPadding property

labelPadding: EdgeInsets.zero,
like image 37
Dan raniego Avatar answered Jul 17 '26 13:07

Dan raniego