Skip to content

TabBar height and vertical text alignment don't match spec #123112

@anthonymoretti

Description

@anthonymoretti

Steps to Reproduce

  1. Execute flutter run on the code sample.
  2. Observe the TabBar height.
  3. Observe the vertical text alignment.

Expected results:
Height and vertical text alignment match the M3 specs.

Actual results:
Height and vertical text alignment don't match the M3 specs.

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = ThemeData.from(
      colorScheme: const ColorScheme.light(),
      textTheme: Typography.englishLike2021,
      useMaterial3: true,
    );

    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Expected results',
                style: theme.textTheme.titleMedium?.copyWith(
                  color: theme.colorScheme.onInverseSurface,
                ),
                textAlign: TextAlign.center,
              ),
              Text(
                'Height: 48.0\n'
                'Text vertically centered',
                style: theme.textTheme.bodyMedium?.copyWith(
                  color: theme.colorScheme.onInverseSurface,
                ),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 16.0),
              DefaultTabController(
                length: 3,
                child: Container(
                  color: theme.colorScheme.surface,
                  child: ConstrainedBox(
                    constraints: const BoxConstraints(maxHeight: 47.5),
                    child: const TabBar(
                      tabs: [
                        Tab(
                          child: Padding(
                            padding: EdgeInsetsDirectional.only(top: 2.5),
                            child: Text('Tab 1'),
                          ),
                        ),
                        Tab(
                          child: Padding(
                            padding: EdgeInsetsDirectional.only(top: 2.5),
                            child: Text('Tab 2'),
                          ),
                        ),
                        Tab(
                          child: Padding(
                            padding: EdgeInsetsDirectional.only(top: 2.5),
                            child: Text('Tab 3'),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              const SizedBox(height: 32.0),
              Text(
                'Actual results',
                style: theme.textTheme.titleMedium?.copyWith(
                  color: theme.colorScheme.onInverseSurface,
                ),
                textAlign: TextAlign.center,
              ),
              Text(
                'Height: 48.67\n'
                'Text not vertically centered',
                style: theme.textTheme.bodyMedium?.copyWith(
                  color: theme.colorScheme.onInverseSurface,
                ),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 16.0),
              DefaultTabController(
                length: 3,
                child: Container(
                  color: theme.colorScheme.surface,
                  child: const TabBar(
                    tabs: [
                      Tab(text: 'Tab 1'),
                      Tab(text: 'Tab 2'),
                      Tab(text: 'Tab 3'),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
        backgroundColor: theme.colorScheme.inverseSurface,
      ),
      theme: theme,
    );
  }
}
Logs
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-x64, locale en-US)
    • Flutter version 3.7.7 on channel stable at /Users/anthonymoretti/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (13 days ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed
      instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed
      instructions).

[✓] VS Code (version 1.76.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • ED506CAA-EB76-47D8-BBDC-751CB0EE7EC8 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)        • macos                                • darwin-x64     • macOS 13.2.1
      22D68 darwin-x64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome
      111.0.5563.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

Tab issue

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions