Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b333fe2

Browse files
authored
Revert "Fix BottomNavigationBar label style text colors" (#102756)
1 parent 9211d7c commit b333fe2

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

packages/flutter/lib/src/material/bottom_navigation_bar.dart

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class BottomNavigationBar extends StatefulWidget {
138138
///
139139
/// If [selectedLabelStyle].color and [unselectedLabelStyle].color values
140140
/// are non-null, they will be used instead of [selectedItemColor] and
141-
/// [unselectedItemColor] to style the label color.
141+
/// [unselectedItemColor].
142142
///
143143
/// If custom [IconThemeData]s are used, you must provide both
144144
/// [selectedIconTheme] and [unselectedIconTheme], and both
@@ -384,7 +384,7 @@ class _BottomNavigationTile extends StatelessWidget {
384384
this.animation,
385385
this.iconSize, {
386386
this.onTap,
387-
this.itemColorTween,
387+
this.colorTween,
388388
this.flex,
389389
this.selected = false,
390390
required this.selectedLabelStyle,
@@ -410,7 +410,7 @@ class _BottomNavigationTile extends StatelessWidget {
410410
final Animation<double> animation;
411411
final double iconSize;
412412
final VoidCallback? onTap;
413-
final ColorTween? itemColorTween;
413+
final ColorTween? colorTween;
414414
final double? flex;
415415
final bool selected;
416416
final IconThemeData? selectedIconTheme;
@@ -513,7 +513,7 @@ class _BottomNavigationTile extends StatelessWidget {
513513
child: _Tile(
514514
layout: layout,
515515
icon: _TileIcon(
516-
itemColorTween: itemColorTween!,
516+
colorTween: colorTween!,
517517
animation: animation,
518518
iconSize: iconSize,
519519
selected: selected,
@@ -522,7 +522,7 @@ class _BottomNavigationTile extends StatelessWidget {
522522
unselectedIconTheme: unselectedIconTheme,
523523
),
524524
label: _Label(
525-
itemColorTween: itemColorTween!,
525+
colorTween: colorTween!,
526526
animation: animation,
527527
item: item,
528528
selectedLabelStyle: selectedLabelStyle,
@@ -602,7 +602,7 @@ class _Tile extends StatelessWidget {
602602

603603
class _TileIcon extends StatelessWidget {
604604
const _TileIcon({
605-
required this.itemColorTween,
605+
required this.colorTween,
606606
required this.animation,
607607
required this.iconSize,
608608
required this.selected,
@@ -612,7 +612,7 @@ class _TileIcon extends StatelessWidget {
612612
}) : assert(selected != null),
613613
assert(item != null);
614614

615-
final ColorTween itemColorTween;
615+
final ColorTween colorTween;
616616
final Animation<double> animation;
617617
final double iconSize;
618618
final bool selected;
@@ -622,7 +622,7 @@ class _TileIcon extends StatelessWidget {
622622

623623
@override
624624
Widget build(BuildContext context) {
625-
final Color? iconColor = itemColorTween.evaluate(animation);
625+
final Color? iconColor = colorTween.evaluate(animation);
626626
final IconThemeData defaultIconTheme = IconThemeData(
627627
color: iconColor,
628628
size: iconSize,
@@ -646,22 +646,22 @@ class _TileIcon extends StatelessWidget {
646646

647647
class _Label extends StatelessWidget {
648648
const _Label({
649-
required this.itemColorTween,
649+
required this.colorTween,
650650
required this.animation,
651651
required this.item,
652652
required this.selectedLabelStyle,
653653
required this.unselectedLabelStyle,
654654
required this.showSelectedLabels,
655655
required this.showUnselectedLabels,
656-
}) : assert(itemColorTween != null),
656+
}) : assert(colorTween != null),
657657
assert(animation != null),
658658
assert(item != null),
659659
assert(selectedLabelStyle != null),
660660
assert(unselectedLabelStyle != null),
661661
assert(showSelectedLabels != null),
662662
assert(showUnselectedLabels != null);
663663

664-
final ColorTween itemColorTween;
664+
final ColorTween colorTween;
665665
final Animation<double> animation;
666666
final BottomNavigationBarItem item;
667667
final TextStyle selectedLabelStyle;
@@ -679,16 +679,10 @@ class _Label extends StatelessWidget {
679679
selectedLabelStyle,
680680
animation.value,
681681
)!;
682-
final ColorTween labelColor = ColorTween(
683-
begin: unselectedLabelStyle.color
684-
?? itemColorTween.begin,
685-
end: selectedLabelStyle.color
686-
?? itemColorTween.end,
687-
);
688682
Widget text = DefaultTextStyle.merge(
689683
style: customStyle.copyWith(
690684
fontSize: selectedFontSize,
691-
color: labelColor.evaluate(animation),
685+
color: colorTween.evaluate(animation),
692686
),
693687
// The font size should grow here when active, but because of the way
694688
// font rendering works, it doesn't grow smoothly if we just animate
@@ -929,10 +923,10 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
929923
break;
930924
}
931925

932-
final ColorTween itemColorTween;
926+
final ColorTween colorTween;
933927
switch (_effectiveType) {
934928
case BottomNavigationBarType.fixed:
935-
itemColorTween = ColorTween(
929+
colorTween = ColorTween(
936930
begin: widget.unselectedItemColor
937931
?? bottomTheme.unselectedItemColor
938932
?? themeData.unselectedWidgetColor,
@@ -943,7 +937,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
943937
);
944938
break;
945939
case BottomNavigationBarType.shifting:
946-
itemColorTween = ColorTween(
940+
colorTween = ColorTween(
947941
begin: widget.unselectedItemColor
948942
?? bottomTheme.unselectedItemColor
949943
?? themeData.colorScheme.surface,
@@ -977,7 +971,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
977971
onTap: () {
978972
widget.onTap?.call(i);
979973
},
980-
itemColorTween: itemColorTween,
974+
colorTween: colorTween,
981975
flex: _evaluateFlex(_animations[i]),
982976
selected: i == widget.currentIndex,
983977
showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels ?? true,

packages/flutter/test/material/bottom_navigation_bar_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ void main() {
140140
});
141141

142142
testWidgets('Custom selected and unselected font styles', (WidgetTester tester) async {
143-
const Color selectedTextColor = Color(0xff00ff00);
144-
const Color unselectedTextColor = Color(0xff0000ff);
145-
const TextStyle selectedTextStyle = TextStyle(color: selectedTextColor, fontWeight: FontWeight.w200, fontSize: 18.0);
146-
const TextStyle unselectedTextStyle = TextStyle(color: unselectedTextColor, fontWeight: FontWeight.w600, fontSize: 12.0);
143+
const TextStyle selectedTextStyle = TextStyle(fontWeight: FontWeight.w200, fontSize: 18.0);
144+
const TextStyle unselectedTextStyle = TextStyle(fontWeight: FontWeight.w600, fontSize: 12.0);
147145

148146
await tester.pumpWidget(
149147
MaterialApp(
@@ -169,10 +167,8 @@ void main() {
169167

170168
final TextStyle selectedFontStyle = tester.renderObject<RenderParagraph>(find.text('AC')).text.style!;
171169
final TextStyle unselectedFontStyle = tester.renderObject<RenderParagraph>(find.text('Alarm')).text.style!;
172-
expect(selectedFontStyle.color, equals(selectedTextColor));
173170
expect(selectedFontStyle.fontSize, equals(selectedTextStyle.fontSize));
174171
expect(selectedFontStyle.fontWeight, equals(selectedTextStyle.fontWeight));
175-
expect(unselectedFontStyle.color, equals(unselectedTextColor));
176172
expect(
177173
tester.firstWidget<Transform>(find.ancestor(of: find.text('Alarm'), matching: find.byType(Transform))).transform,
178174
equals(Matrix4.diagonal3(Vector3.all(unselectedTextStyle.fontSize! / selectedTextStyle.fontSize!))),

0 commit comments

Comments
 (0)