Skip to content

[Material3] TabBar indicator stretch effect behaving weirdly with long tabs #149662

@adigladi

Description

@adigladi

Steps to reproduce

Create a TabBar with some text tabs in different lengths, even with some that are truncated. TabBar can be scrollable or not (but issue is more prominent with scrollable).

Expected results

The TabBar indicator should animate smoothly even with tabs with longer text, without expanding in opposite direction of slide animation.

Actual results

Indicator first expands to the left (if navigating to the right) while extending width of indicator. This expanding to the left does not seem to happen on shorter tabs and causes the animation to look glitchy. Also if swiping quickly between screens/tabs this becomes very jarring.

The new _applyStretchEffect method used in tabs.dart seems to be making the indicator behave weirdly when tabs with longer text is used. I tried setting final double stretchSize = rect.width; to half or a quarter, which seems to help with the expanding width animation a bit, but it's not perfect.

The best solution (for the project I'm working on at least) would be to have _applyStretchEffect as an optional parameter, as disabling it works best for the scrolling use case (according to me). But this might not go in line with the material spec?

Code sample

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) {
    return const MaterialApp(
      home: DefaultTabController(
        length: 8,
        child: SafeArea(
          child: Scaffold(
            appBar: TabBar(
              isScrollable: true,
              tabAlignment: TabAlignment.center,
              tabs: [
                Tab(text: 'Home'),
                Tab(text: 'Search'),
                Tab(text: 'Add'),
                Tab(text: 'Favorite'),
                Tab(text: 'The longest text...'),
                Tab(text: 'Short'),
                Tab(text: 'Longer text...'),
                Tab(text: 'Profile'),
              ],
            ),
            body: TabBarView(
              children: <Widget>[
                Center(child: Text("Page")),
                Center(child: Text("Page")),
                Center(child: Text("Page")),
                Center(child: Text("Page")),
                Center(child: Text("Page")),
                Center(child: Text("Page")),
                Center(child: Text("Page")),
                Center(child: Text("Page")),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

Example of jarring animation:

RPReplay_Final1717514051.MP4
RPReplay_Final1717514442.MP4

With final double stretchSize = rect.width / 2;

RPReplay_Final1717514092.MP4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale en-SE)
    • Flutter version 3.22.1 on channel stable at /Users/<user>/fvm/versions/3.22.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a14f74ff3a (13 days ago), 2024-05-22 11:08:21 -0500
    • Engine revision 55eae6864b
    • Dart version 3.4.1
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/<user>/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/<user>/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2023.1)
    • 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 17.0.7+0-17.0.7b1000.6-10550314)

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

[✓] VS Code (version 1.83.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.72.0

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.found in release: 3.22Found to occur in 3.22found in release: 3.23Found to occur in 3.23frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: 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