Commit de2dbf4
authored
Fix
fixes [[Material3] TabBar indicator stretch effect behaving weirdly with long tabs](flutter/flutter#149662)
This PR fixes the tab indicator stretch effect, it currently stretches from both sides. After the fix, tab indicator stretches depending on next size of the indicator and direction of the scroll.
The fix is based on Android Components implementation of the elastic/stretch effect.
https://github.com/material-components/material-components-android/blob/20f92dfb513916d0df6c38bfd630dfc41aff484e/lib/java/com/google/android/material/tabs/ElasticTabIndicatorInterpolator.java#L46-L78
### Code sample
<details>
<summary>expand to view the code sample</summary>
```dart
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: ScrollConfiguration(
behavior: ScrollConfiguration.of(context)
.copyWith(dragDevices: <PointerDeviceKind>{
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
}),
child: DefaultTabController(
length: 8,
child: Scaffold(
appBar: AppBar(
bottom: const TabBar(
isScrollable: true,
tabAlignment: TabAlignment.start,
tabs: <Widget>[
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: const 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')),
],
),
),
),
),
);
}
}
```
</details>
### Before
https://github.com/flutter/flutter/assets/48603081/618d0ba9-40a5-458f-9fdc-5330505a6711
### After
https://github.com/flutter/flutter/assets/48603081/b7fa851e-e7a6-4b66-b77d-f88c7f4381daTabBar tab indicator stretch effect (#150868)1 parent 0c21fbc commit de2dbf4
2 files changed
Lines changed: 55 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | | - | |
| 557 | + | |
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
578 | 588 | | |
579 | | - | |
| 589 | + | |
580 | 590 | | |
581 | 591 | | |
582 | 592 | | |
| |||
586 | 596 | | |
587 | 597 | | |
588 | 598 | | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
| 599 | + | |
605 | 600 | | |
606 | 601 | | |
607 | 602 | | |
608 | 603 | | |
609 | 604 | | |
610 | 605 | | |
611 | | - | |
612 | | - | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
613 | 610 | | |
614 | | - | |
615 | | - | |
| 611 | + | |
616 | 612 | | |
617 | 613 | | |
618 | 614 | | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | 615 | | |
638 | | - | |
639 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
640 | 623 | | |
641 | 624 | | |
642 | 625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
2454 | 2457 | | |
2455 | 2458 | | |
2456 | 2459 | | |
2457 | | - | |
| 2460 | + | |
2458 | 2461 | | |
2459 | 2462 | | |
2460 | 2463 | | |
| |||
2483 | 2486 | | |
2484 | 2487 | | |
2485 | 2488 | | |
2486 | | - | |
2487 | 2489 | | |
2488 | | - | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
2489 | 2500 | | |
2490 | | - | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
2491 | 2505 | | |
2492 | | - | |
| 2506 | + | |
2493 | 2507 | | |
2494 | | - | |
| 2508 | + | |
2495 | 2509 | | |
2496 | 2510 | | |
2497 | 2511 | | |
| |||
2500 | 2514 | | |
2501 | 2515 | | |
2502 | 2516 | | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
2503 | 2520 | | |
2504 | | - | |
| 2521 | + | |
2505 | 2522 | | |
2506 | 2523 | | |
2507 | 2524 | | |
2508 | 2525 | | |
2509 | | - | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
2510 | 2529 | | |
2511 | 2530 | | |
2512 | 2531 | | |
2513 | 2532 | | |
2514 | | - | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
2515 | 2536 | | |
2516 | 2537 | | |
2517 | 2538 | | |
| |||
0 commit comments