@@ -15,7 +15,6 @@ import 'color_scheme.dart';
15
15
import 'colors.dart' ;
16
16
import 'constants.dart' ;
17
17
import 'debug.dart' ;
18
- import 'divider.dart' ;
19
18
import 'ink_well.dart' ;
20
19
import 'material.dart' ;
21
20
import 'material_localizations.dart' ;
@@ -361,6 +360,7 @@ class _IndicatorPainter extends CustomPainter {
361
360
required _IndicatorPainter ? old,
362
361
required this .indicatorPadding,
363
362
required this .labelPaddings,
363
+ this .dividerColor,
364
364
}) : super (repaint: controller.animation) {
365
365
if (old != null ) {
366
366
saveTabOffsets (old._currentTabOffsets, old._currentTextDirection);
@@ -372,6 +372,7 @@ class _IndicatorPainter extends CustomPainter {
372
372
final TabBarIndicatorSize ? indicatorSize;
373
373
final EdgeInsetsGeometry indicatorPadding;
374
374
final List <GlobalKey > tabKeys;
375
+ final Color ? dividerColor;
375
376
final List <EdgeInsetsGeometry > labelPaddings;
376
377
377
378
// _currentTabOffsets and _currentTextDirection are set each time TabBar
@@ -464,6 +465,10 @@ class _IndicatorPainter extends CustomPainter {
464
465
size: _currentRect! .size,
465
466
textDirection: _currentTextDirection,
466
467
);
468
+ if (dividerColor != null ) {
469
+ final Paint dividerPaint = Paint ()..color = dividerColor! ..strokeWidth = 1 ;
470
+ canvas.drawLine (Offset (0 , size.height), Offset (size.width, size.height), dividerPaint);
471
+ }
467
472
_painter! .paint (canvas, _currentRect! .topLeft, configuration);
468
473
}
469
474
@@ -677,7 +682,6 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
677
682
this .indicator,
678
683
this .indicatorSize,
679
684
this .dividerColor,
680
- this .dividerHeight,
681
685
this .labelColor,
682
686
this .labelStyle,
683
687
this .labelPadding,
@@ -727,7 +731,6 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
727
731
this .indicator,
728
732
this .indicatorSize,
729
733
this .dividerColor,
730
- this .dividerHeight,
731
734
this .labelColor,
732
735
this .labelStyle,
733
736
this .labelPadding,
@@ -846,13 +849,6 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
846
849
/// [ColorScheme.surfaceVariant] will be used, otherwise divider will not be drawn.
847
850
final Color ? dividerColor;
848
851
849
- /// The height of the divider.
850
- ///
851
- /// If null and [ThemeData.useMaterial3] is true, [TabBarTheme.dividerHeight]
852
- /// is used. If that is null and [ThemeData.useMaterial3] is true, 1.0 will be used.
853
- /// Otherwise divider will not be drawn.
854
- final double ? dividerHeight;
855
-
856
852
/// The color of selected tab labels.
857
853
///
858
854
/// If null, then [TabBarTheme.labelColor] is used. If that is also null and
@@ -1100,7 +1096,7 @@ class _TabBarState extends State<TabBar> {
1100
1096
}
1101
1097
}
1102
1098
1103
- Decoration _getIndicator (TabBarIndicatorSize indicatorSize ) {
1099
+ Decoration _getIndicator () {
1104
1100
final ThemeData theme = Theme .of (context);
1105
1101
final TabBarTheme tabBarTheme = TabBarTheme .of (context);
1106
1102
@@ -1134,24 +1130,17 @@ class _TabBarState extends State<TabBar> {
1134
1130
color = Colors .white;
1135
1131
}
1136
1132
1137
- if (theme.useMaterial3 && widget._isPrimary && indicatorSize == TabBarIndicatorSize .label) {
1138
- return UnderlineTabIndicator (
1139
- borderRadius: const BorderRadius .only (
1140
- topLeft: Radius .circular (3.0 ),
1141
- topRight: Radius .circular (3.0 ),
1142
- ),
1143
- borderSide: BorderSide (
1133
+ return UnderlineTabIndicator (
1134
+ borderRadius: theme.useMaterial3 && widget._isPrimary
1144
1135
// TODO(tahatesser): Make sure this value matches Material 3 Tabs spec
1145
1136
// when `preferredSize`and `indicatorWeight` are updated to support Material 3
1146
1137
// https://m3.material.io/components/tabs/specs#149a189f-9039-4195-99da-15c205d20e30,
1147
1138
// https://github.com/flutter/flutter/issues/116136
1148
- width: widget.indicatorWeight,
1149
- color: color,
1150
- ),
1151
- );
1152
- }
1153
-
1154
- return UnderlineTabIndicator (
1139
+ ? const BorderRadius .only (
1140
+ topLeft: Radius .circular (3.0 ),
1141
+ topRight: Radius .circular (3.0 ),
1142
+ )
1143
+ : null ,
1155
1144
borderSide: BorderSide (
1156
1145
width: widget.indicatorWeight,
1157
1146
color: color,
@@ -1196,18 +1185,17 @@ class _TabBarState extends State<TabBar> {
1196
1185
}
1197
1186
1198
1187
void _initIndicatorPainter () {
1188
+ final ThemeData theme = Theme .of (context);
1199
1189
final TabBarTheme tabBarTheme = TabBarTheme .of (context);
1200
- final TabBarIndicatorSize indicatorSize = widget.indicatorSize
1201
- ?? tabBarTheme.indicatorSize
1202
- ?? _defaults.indicatorSize! ;
1203
1190
1204
1191
_indicatorPainter = ! _controllerIsValid ? null : _IndicatorPainter (
1205
1192
controller: _controller! ,
1206
- indicator: _getIndicator (indicatorSize ),
1207
- indicatorSize: indicatorSize,
1193
+ indicator: _getIndicator (),
1194
+ indicatorSize: widget. indicatorSize ?? tabBarTheme.indicatorSize ?? _defaults.indicatorSize ! ,
1208
1195
indicatorPadding: widget.indicatorPadding,
1209
1196
tabKeys: _tabKeys,
1210
1197
old: _indicatorPainter,
1198
+ dividerColor: theme.useMaterial3 ? widget.dividerColor ?? tabBarTheme.dividerColor ?? _defaults.dividerColor : null ,
1211
1199
labelPaddings: _labelPaddings,
1212
1200
);
1213
1201
}
@@ -1402,7 +1390,6 @@ class _TabBarState extends State<TabBar> {
1402
1390
);
1403
1391
}
1404
1392
1405
- final ThemeData theme = Theme .of (context);
1406
1393
final TabBarTheme tabBarTheme = TabBarTheme .of (context);
1407
1394
1408
1395
final List <Widget > wrappedTabs = List <Widget >.generate (widget.tabs.length, (int index) {
@@ -1548,24 +1535,6 @@ class _TabBarState extends State<TabBar> {
1548
1535
);
1549
1536
}
1550
1537
1551
- if (theme.useMaterial3) {
1552
- tabBar = Stack (
1553
- alignment: Alignment .center,
1554
- children: < Widget > [
1555
- Container (
1556
- height: widget.preferredSize.height,
1557
- alignment: Alignment .bottomCenter,
1558
- child: Divider (
1559
- height: 0 ,
1560
- thickness: widget.dividerHeight ?? tabBarTheme.dividerHeight ?? _defaults.dividerHeight,
1561
- color: widget.dividerColor ?? tabBarTheme.dividerColor ?? _defaults.dividerColor,
1562
- ),
1563
- ),
1564
- tabBar,
1565
- ],
1566
- );
1567
- }
1568
-
1569
1538
return tabBar;
1570
1539
}
1571
1540
}
@@ -2099,9 +2068,6 @@ class _TabsPrimaryDefaultsM3 extends TabBarTheme {
2099
2068
late final ColorScheme _colors = Theme .of (context).colorScheme;
2100
2069
late final TextTheme _textTheme = Theme .of (context).textTheme;
2101
2070
2102
- @override
2103
- double ? get dividerHeight => 1.0 ;
2104
-
2105
2071
@override
2106
2072
Color ? get dividerColor => _colors.surfaceVariant;
2107
2073
@@ -2163,9 +2129,6 @@ class _TabsSecondaryDefaultsM3 extends TabBarTheme {
2163
2129
@override
2164
2130
Color ? get dividerColor => _colors.surfaceVariant;
2165
2131
2166
- @override
2167
- double ? get dividerHeight => 1.0 ;
2168
-
2169
2132
@override
2170
2133
Color ? get indicatorColor => _colors.primary;
2171
2134
0 commit comments