Skip to content

TabBar.height adds a gap between the AppBar.toolbar and AppBar.bottom #156200

Closed

Description

@benji-farquhar

Use case

If we add a smaller height to TabBar, E.G:
AppBar(
  bottom: const TabBar(
    tabs: [
      Tab(
        text: 'Profile',
        height: 30,
      ),
      Tab(
        text: 'Appearance',
        height: 30,
      ),
    ],
  ),
It adds a gap between the `AppBar` `toolbar` and the `bottom`:
Screenshot 2024-10-04 at 8 32 59 pm

And without the height specified on the Tab, it has no gap:

Screenshot 2024-10-04 at 8 31 39 pm

I don't want the gap. So i want this:

Screenshot 2024-10-04 at 8 35 25 pm

Proposal

Ideally we should be able to control the padding between them but i found just adding mainAxisSize: MainAxisSize.min, below to app_bar.dart at least removed the gap entirely which is better than mandatory gap:

if (widget.bottom != null) {
  appBar = Column(
    mainAxisSize: MainAxisSize.min,
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: <Widget>[
      Flexible(
        child: ConstrainedBox(
          constraints: BoxConstraints(maxHeight: toolbarHeight),
          child: appBar,
        ),
      ),
      if (widget.bottomOpacity == 1.0)
        widget.bottom!
      else
        Opacity(
          opacity: const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.bottomOpacity),
          child: widget.bottom,
        ),
    ],
  );

Adding this between them gave the padding desired: SizedBox(height: 5), so ideally you would add bottomSpacer as a parameter to customise: SizedBox(height: bottomSpacer), or make it EdgeInsets and wrap the bottom with it.

Activity

  1. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    c: proposalA detailed proposal for a change to Flutter
    team-designOwned by Design Languages team
    c: new featureNothing broken; request for a new capability
    and removed
    in triagePresently being triaged by the triage team
    on Oct 4, 2024
  2. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    and removed
    c: new featureNothing broken; request for a new capability
    c: proposalA detailed proposal for a change to Flutter
    on Oct 10, 2024
  3. self-assigned this
    on Oct 21, 2024
  4. TahaTesser commented on Oct 22, 2024

    @TahaTesser
    Contributor

    @Piinks

    This is by design. When the tabs height is less than the default _kTabHeight then it defaults to the value of _kTabHeight (46 pixels)

    @override
    Size get preferredSize {
    double maxHeight = _kTabHeight;
    for (final Widget item in tabs) {
    if (item is PreferredSizeWidget) {
    final double itemHeight = item.preferredSize.height;
    maxHeight = math.max(itemHeight, maxHeight);
    }
    }

    If we want to change this behavior, to avoid breaking change we would need to some sort of parameter.

  5. Piinks commented on Oct 22, 2024

    @Piinks
    Contributor

    Ah right, thanks for taking a look. Should we add to the docs that TabBars cannot be less than 46 pixels in height?

  6. TahaTesser commented on Oct 22, 2024

    @TahaTesser
    Contributor

    Ah right, thanks for taking a look. Should we add to the docs that TabBars cannot be less than 46 pixels in height?

    +1 and I remember folks using PreferredSize for a custom tab bar. It can be leveraged to get a smaller than default tab bar.

                bottom: const PreferredSize(
                  preferredSize: Size.fromHeight(20),
                  child: TabBar(
                    tabs: [
                      Tab(
                        text: 'Profile',
                        height: 20,
                      ),
                      Tab(
                        text: 'Appearance',
                        height: 20,
                      ),
                    ],
                  ),
                ),
    Screenshot 2024-10-22 at 18 29 23
  7. moved this from To do to In progress in Nevercodeon Oct 22, 2024
  8. moved this from In progress to PR submitted in Nevercodeon Oct 23, 2024
  9. moved this from PR submitted to Done (PR merged) in Nevercodeon Oct 24, 2024
  10. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 24, 2024
  11. github-actions commented on Nov 7, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions