skip to Main Content

I’m getting a bottom underline in the TabBar. I tried to remove it. but its not removing.

(https://i.sstatic.net/CbDf57Nr.png)

Widget build(BuildContext context) {
    TabController tabController = TabController(length: 2, vsync: this);
  return Scaffold(
      backgroundColor: Palette.white,
      body:  Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              decoration: BoxDecoration(color: const Color(0x1E767680), borderRadius: BorderRadius.circular(7)),
              height: 36,
              child: TabBar(
                indicatorSize: TabBarIndicatorSize.tab,
                indicatorPadding: const EdgeInsets.all(2),
                indicator: BoxDecoration(
                  borderRadius: BorderRadius.circular(7),
                  color: Colors.deepPurple,
                ),
                controller: tabController,
                labelStyle: const TextStyle(color: Colors.white, fontSize: 13, fontWeight: FontWeight.w500),
                unselectedLabelStyle: const TextStyle(color: Color(0xFF5B5B5B), fontSize: 13, fontWeight: FontWeight.w400),
                indicatorWeight: 0,
                indicatorColor: Colors.transparent,
                tabs: const [
                  Tab(text: 'Page 1'),
                  Tab(text: 'Page 2'),
                ],
              ),
            ),

            const SizedBox(height: 16),
            //TabBarView
            Expanded(
              child: TabBarView(
                controller: tabController,
                children: [
                  _buildAttendanceView(),
                  Tab2(),
                ],
              ),
            )
          ],
        ), );

I tried,
border: Border.all(color: Colors.transparent) to remove any visible border.
indicatorWeight: 0:
indicatorColor: Colors.transparent:
Wrap the TabBar widget inside a Material widget and set borderOnForeground to false.
but didnt work.

2

Answers


  1. It sounds like you’re dealing with an unwanted underline or border at the bottom of the TabBar. You’ve already tried some approaches like setting indicatorWeight to 0, indicatorColor to transparent, and wrapping the TabBar in a Material widget, but the underline persists.

    To remove the underline, try the following adjustments:

    1. Set the indicator to null:

    If you don’t want any underline or indicator at all, you can set the indicator property of the TabBar to null.

    2. Remove the indicatorWeight:

    Ensure that the indicatorWeight is completely removed since setting it to 0 might still cause issues.

    Here’s how your code could look with these adjustments:

    Widget build(BuildContext context) {
      TabController tabController = TabController(length: 2, vsync: this);
      return Scaffold(
        backgroundColor: Palette.white,
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              decoration: BoxDecoration(
                color: const Color(0x1E767680), 
                borderRadius: BorderRadius.circular(7)
              ),
              height: 36,
              child: TabBar(
                controller: tabController,
                indicator: BoxDecoration(
                  borderRadius: BorderRadius.circular(7),
                  color: Colors.deepPurple,
                ),
                labelStyle: const TextStyle(
                  color: Colors.white, 
                  fontSize: 13, 
                  fontWeight: FontWeight.w500
                ),
                unselectedLabelStyle: const TextStyle(
                  color: Color(0xFF5B5B5B), 
                  fontSize: 13, 
                  fontWeight: FontWeight.w400
                ),
                tabs: const [
                  Tab(text: 'Page 1'),
                  Tab(text: 'Page 2'),
                ],
              ),
            ),
            const SizedBox(height: 16),
            // TabBarView
            Expanded(
              child: TabBarView(
                controller: tabController,
                children: [
                  _buildAttendanceView(),
                  Tab2(),
                ],
              ),
            ),
          ],
        ),
      );
    }
    

    3. Ensure the TabBar is not inside a Material widget with a borderOnForeground setting:

    If you have wrapped the TabBar inside a Material widget elsewhere, ensure that borderOnForeground is not interfering.

    4. Check for Other Widgets:

    If none of the above works, double-check other widgets wrapping the TabBar, like Container or any parent Material widget, to ensure they aren’t causing any unintended styling issues.

    This should resolve the unwanted underline in the TabBar. If the issue persists, please let me know, and we can explore further adjustments.

    Login or Signup to reply.
  2. Try below code, add dividerColor: Colors.transparent, Read more about dividerColor

    Scaffold(
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            decoration: BoxDecoration(
                color: const Color(0x1E767680),
                borderRadius: BorderRadius.circular(7)),
            height: 36,
            child: TabBar(
              indicatorSize: TabBarIndicatorSize.tab,
              indicatorPadding: const EdgeInsets.all(2),
              indicator: BoxDecoration(
                borderRadius: BorderRadius.circular(7),
                color: Colors.deepPurple,
              ),
              controller: tabController,
              labelStyle: const TextStyle(
                  color: Colors.white,
                  fontSize: 13,
                  fontWeight: FontWeight.w500),
              unselectedLabelStyle: const TextStyle(
                  color: Color(0xFF5B5B5B),
                  fontSize: 13,
                  fontWeight: FontWeight.w400),
              indicatorWeight: 0,
              dividerColor: Colors.transparent,
              indicatorColor: Colors.transparent,
              tabs: const [
                Tab(text: 'Page 1'),
                Tab(text: 'Page 2'),
              ],
            ),
          ),
    
          const SizedBox(height: 16),
          //TabBarView
          Expanded(
            child: TabBarView(
              controller: tabController,
              children: [
                Center(
                  child: Text("Page 1"),
                ),
                Center(
                  child: Text("Page 2"),
                ),
              ],
            ),
          )
        ],
      ),
    );
    

    Result-> image

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search