Skip to content

TabBar shadows are clipped and indicator height cannot be reduced #59728

Open

Description

@sanisloandras

Hello!

To understand what am I trying to achieve, have a look at the attached image.
Screenshot 2020-06-18 at 3 36 51

But as you can see, the tab's shadow can not fit inside the Tab. So how do I make space for the shadow?
Also, how do I change the indicators size? For example, I want to make my tabs indicator height smaller.
I can't find any way to configure that.

Here is how I build a Tab:

Tab buildTab(CategoryModel category) {
    return Tab(child: ConstrainedBox(
      constraints: BoxConstraints(
        minWidth: 48,
      ),
      child: Text(category.name, textAlign: TextAlign.center,),
    ),);
  }

And this is how I builde the TabBar:

return TabBar(
      indicator: BoxDecoration(
          color: Colors.blue,
          borderRadius: const BorderRadius.all(
            const Radius.circular(999.0),
          ),
          boxShadow: const [BoxShadow(color: Colors.blueAccent, blurRadius: 6.0)]
      ),
      unselectedLabelColor: Colors.blue,
      labelColor: Colors.white,
      isScrollable: true,
      tabs: tabs,
    );

Activity

  1. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jun 18, 2020
  2. payam-zahedi commented on Aug 6, 2020

    @payam-zahedi
    Contributor

    @shihaohong @pedromassango @TahaTesser hi guys, I want to create PR for this issue. do you have any idea about how can I solve this?
    I fork the repo and clone it should I work on a stable branch? or should I use master branch for PR?

  3. emem365 commented on Aug 7, 2020

    @emem365
    Contributor

    Hi @sanisloandras, I looked into the code a bit to see how this is implemented. Basically, the way these indicators are implemented is by using a CustomPainter, which creates a sort of rectangular canvas according to the size of the tabs, and then draws the indicator on it. Now CustomPainters cannot really paint outside the canvas, hence, the shadow cannot go outside. So your best bet at this point would be, either to get rid of the shadow, or to try and find a workaround with indicator size.

    Regarding that, TabBar has a property called indicatorSize this is is how the comments in the code define it

      /// Defines how the selected tab indicator's size is computed.
      ///
      /// The size of the selected tab indicator is defined relative to the
      /// tab's overall bounds if [indicatorSize] is [TabBarIndicatorSize.tab]
      /// (the default) or relative to the bounds of the tab's widget if
      /// [indicatorSize] is [TabBarIndicatorSize.label].
      ///
      /// The selected tab's location appearance can be refined further with
      /// the [indicatorColor], [indicatorWeight], [indicatorPadding], and
      /// [indicator] properties.
      final TabBarIndicatorSize indicatorSize;
    

    Here TabBarIndicatorSize is an enum :

    enum TabBarIndicatorSize {
      /// The tab indicator's bounds are as wide as the space occupied by the tab
      /// in the tab bar: from the right edge of the previous tab to the left edge
      /// of the next tab.
      tab,
    
      /// The tab's bounds are only as wide as the (centered) tab widget itself.
      ///
      /// This value is used to align the tab's label, typically a [Tab]
      /// widget's text or icon, with the selected tab indicator.
      label,
    }
    

    See, if any of those work for your needs.

    For example, I want to make my tabs indicator height smaller.
    I can't find any way to configure that.

    To decrease the height, I couldn't find anything yet, my first guess was that you could probably work with the property indicatorPadding:

      /// The horizontal padding for the line that appears below the selected tab.
      ///
      /// For [isScrollable] tab bars, specifying [kTabLabelPadding] will align
      /// the indicator with the tab's text for [Tab] widgets and all but the
      /// shortest [Tab.text] values.
      ///
      /// The [EdgeInsets.top] and [EdgeInsets.bottom] values of the
      /// [indicatorPadding] are ignored.
      ///
      /// The default value of [indicatorPadding] is [EdgeInsets.zero].
      ///
      /// If [indicator] is specified or provided from [TabBarTheme],
      /// this property is ignored.
      final EdgeInsetsGeometry indicatorPadding;
    

    but as it says EdgeInsets.top and bottom are ignored, I think you'll need something else. Iam not really sure at this point, maybe someone else can help with that, or maybe we really need a PR to implement this thing. I'll try to figure this out a bit, and comment back if I find something

  4. emem365 commented on Aug 7, 2020

    @emem365
    Contributor

    I am pretty new to open source and trying to see if I can contribute to flutter somehow.
    @TahaTesser , if you could maybe point me in the right direction, I'd like to help with this issue :)

    Can we extend Decoration class and use it to create a Custom Indicator according to our needs? I guess, this could work?

  5. shihaohong commented on Aug 10, 2020

    @shihaohong
    Contributor

    It seems like one approach for making the shadows fit inside the tab bar is to increase the size of the tab bar itself, since the shadows are being clipped from not being able to fit vertically.

    As for the indicator size itself, you'll need to look closer into the indicator paint logic, since I'm not exactly sure how that's defined and how to modify it. My hunch is that it's currently set at the default height of 48px to adhere to the Material accessibility guidelines. However, it's okay to make it possible to specify a non-default height for the indicator or the widget that the indicator wraps.

    It looks like this issue can be broken down into two separate fixes:

    • Modifying the tab's internal height/padding (to make space for the shadows)
    • Customize the tab indicator's height.

    @emem365 @payam-zahedi Look at https://github.com/flutter/flutter/blob/master/CONTRIBUTING.md for more specifics on Flutter's contributing workflow, but I think the best way to start is to get through that, fix the issue in your own fork in a new branch, and then submit a PR for code review.

  6. changed the title [-]TabBar improvements[/-] [+]TabBar shadows are clipped and indicator height cannot be reduced[/+] on Aug 10, 2020
  7. emem365 commented on Aug 11, 2020

    @emem365
    Contributor

    ok @shihaohong, I'll try to submit a PR soon :)

  8. emem365 commented on Aug 13, 2020

    @emem365
    Contributor

    Hey, @shihaohong. I looked into what you suggested, and I tried to work some stuff out. I have tried to make it possible for us to change internal padding while painting the indicator.

    I have created a PR and I had some doubts with the stuff I was doing in the PR. Like, originally, the property indicatorPadding was being used only when using the default UnderlineTabIndicator and would work for only horizontal padding. If I add ability to add indicatorPadding to the _IndicatorPainter, that makes me not give any insets property to the UnderlineTabIndicator. Also, we can no longer ignore the vertical padding in this case.
    If someone could please, take a look at the PR (#63683) and give their opinion on if I am doing this right or not That would be really helpful.

    Also, with respect to the fixes you suggested:

    • Modifying the tab's internal height/padding (to make space for the shadows)
    • Customize the tab indicator's height.
      Do you think I should still work on the height somehow?
  9. 6 remaining items

  10. nzackoya commented on Feb 22, 2022

    @nzackoya

    indicatorPadding fixes the issue I guess

  11. maheshj01 commented on Dec 24, 2022

    @maheshj01
    Member

    I am able to reproduce the issue on stable 3.3 and master 3.7 also notice the selected tab is going out of TabBar.

    image

    flutter doctor -v (mac)
    [✓] Flutter (Channel master, 3.7.0-3.0.pre.33, on macOS 12.6 21G115 darwin-arm64, locale en-IN)
        • Flutter version 3.7.0-3.0.pre.33 on channel master 
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 5201856805 (38 minutes ago), 2022-12-05 18:27:21 -0800
        • Engine revision a309d239c4
        • Dart version 2.19.0 (build 2.19.0-463.0.dev)
        • DevTools version 2.20.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly
          to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.70.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.55.20221129
    
    [✓] Connected device (3 available)
        • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 108.0.5359.94
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-IN)
        • Flutter version 3.3.9 on channel stable at /Users/mahesh/Development/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b8f7f1f986 (24 hours ago), 2022-11-23 06:43:51 +0900
        • Engine revision 8f2221fbef
        • Dart version 2.18.5
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.70.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.53.20221101
    
    [✓] Connected device (3 available)
        • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.110
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  12. added
    c: new featureNothing broken; request for a new capability
    P3Issues that are less important to the Flutter project
    workaround availableThere is a workaround available to overcome the issue
    on Mar 4, 2025
  13. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityfound in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions