Commit 32fde13
authored
Fix Material 3 Scrollable
fix flutter#117722
### Description
1. Fix the divider doesn't stretch to take all the available width in the scrollable tab bar in M3
2. Add `dividerHeight` property.
3. Update the default tab alignment for the scrollable tab bar to match the specs (this is backward compatible for M2 with the new `tabAlignment` property).
### Bug (default tab alignment)

### Fix (default tab alignment)

### Code sample
<details>
<summary>code sample</summary>
```dart
import 'package:flutter/material.dart';
/// Flutter code sample for [TabBar].
void main() => runApp(const TabBarApp());
class TabBarApp extends StatelessWidget {
const TabBarApp({super.key});
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
// tabBarTheme: const TabBarTheme(tabAlignment: TabAlignment.start),
useMaterial3: true,
),
home: const TabBarExample(),
);
}
}
class TabBarExample extends StatefulWidget {
const TabBarExample({super.key});
@OverRide
State<TabBarExample> createState() => _TabBarExampleState();
}
class _TabBarExampleState extends State<TabBarExample> {
bool rtl = false;
@OverRide
Widget build(BuildContext context) {
return DefaultTabController(
initialIndex: 1,
length: 3,
child: Directionality(
textDirection: rtl ? TextDirection.rtl : TextDirection.ltr,
child: Scaffold(
appBar: AppBar(
title: const Text('TabBar Sample'),
),
body: const Column(
children: <Widget>[
Text('Scrollable-TabAlignment.start'),
TabBar(
isScrollable: true,
tabAlignment: TabAlignment.start,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
Text('Scrollable-TabAlignment.startOffset'),
TabBar(
isScrollable: true,
tabAlignment: TabAlignment.startOffset,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
Text('Scrollable-TabAlignment.center'),
TabBar(
isScrollable: true,
tabAlignment: TabAlignment.center,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
Spacer(),
Text('Non-scrollable-TabAlignment.fill'),
TabBar(
tabAlignment: TabAlignment.fill,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
Text('Non-scrollable-TabAlignment.center'),
TabBar(
tabAlignment: TabAlignment.center,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
Spacer(),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
setState(() {
rtl = !rtl;
});
},
label: const Text('Switch Direction'),
icon: const Icon(Icons.swap_horiz),
),
),
),
);
}
}
```
</details>
TabBar (flutter#125974)1 parent 0da8012 commit 32fde13
File tree
6 files changed
+624
-43
lines changed- dev/tools/gen_defaults
- generated
- lib
- packages/flutter
- lib/src/material
- test/material
6 files changed
+624
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
| 532 | + | |
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
| |||
588 | 589 | | |
589 | 590 | | |
590 | 591 | | |
| 592 | + | |
591 | 593 | | |
592 | 594 | | |
593 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | | - | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
138 | | - | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| 108 | + | |
104 | 109 | | |
105 | 110 | | |
106 | 111 | | |
| |||
116 | 121 | | |
117 | 122 | | |
118 | 123 | | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
| |||
147 | 153 | | |
148 | 154 | | |
149 | 155 | | |
| 156 | + | |
150 | 157 | | |
151 | 158 | | |
152 | 159 | | |
| |||
165 | 172 | | |
166 | 173 | | |
167 | 174 | | |
| 175 | + | |
168 | 176 | | |
169 | 177 | | |
170 | 178 | | |
| |||
189 | 197 | | |
190 | 198 | | |
191 | 199 | | |
| 200 | + | |
192 | 201 | | |
193 | 202 | | |
194 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
| 400 | + | |
| 401 | + | |
400 | 402 | | |
401 | 403 | | |
402 | 404 | | |
| |||
408 | 410 | | |
409 | 411 | | |
410 | 412 | | |
411 | | - | |
412 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
| |||
502 | 506 | | |
503 | 507 | | |
504 | 508 | | |
505 | | - | |
506 | | - | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
507 | 513 | | |
508 | 514 | | |
509 | 515 | | |
| |||
718 | 724 | | |
719 | 725 | | |
720 | 726 | | |
| 727 | + | |
721 | 728 | | |
722 | 729 | | |
723 | 730 | | |
| |||
768 | 775 | | |
769 | 776 | | |
770 | 777 | | |
| 778 | + | |
771 | 779 | | |
772 | 780 | | |
773 | 781 | | |
| |||
895 | 903 | | |
896 | 904 | | |
897 | 905 | | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
898 | 913 | | |
899 | 914 | | |
900 | 915 | | |
| |||
1154 | 1169 | | |
1155 | 1170 | | |
1156 | 1171 | | |
1157 | | - | |
1158 | | - | |
| 1172 | + | |
| 1173 | + | |
1159 | 1174 | | |
1160 | 1175 | | |
1161 | 1176 | | |
| |||
1269 | 1284 | | |
1270 | 1285 | | |
1271 | 1286 | | |
1272 | | - | |
1273 | 1287 | | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
1274 | 1291 | | |
1275 | 1292 | | |
1276 | 1293 | | |
| |||
1475 | 1492 | | |
1476 | 1493 | | |
1477 | 1494 | | |
| 1495 | + | |
1478 | 1496 | | |
1479 | 1497 | | |
1480 | 1498 | | |
| |||
1627 | 1645 | | |
1628 | 1646 | | |
1629 | 1647 | | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
1630 | 1659 | | |
1631 | 1660 | | |
1632 | 1661 | | |
| |||
2177 | 2206 | | |
2178 | 2207 | | |
2179 | 2208 | | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
2180 | 2212 | | |
2181 | 2213 | | |
2182 | 2214 | | |
| |||
2224 | 2256 | | |
2225 | 2257 | | |
2226 | 2258 | | |
2227 | | - | |
| 2259 | + | |
2228 | 2260 | | |
2229 | 2261 | | |
2230 | 2262 | | |
| |||
2241 | 2273 | | |
2242 | 2274 | | |
2243 | 2275 | | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
2244 | 2279 | | |
2245 | 2280 | | |
2246 | 2281 | | |
| |||
2288 | 2323 | | |
2289 | 2324 | | |
2290 | 2325 | | |
2291 | | - | |
| 2326 | + | |
2292 | 2327 | | |
2293 | 2328 | | |
2294 | 2329 | | |
0 commit comments