Skip to content

Commit 9608a64

Browse files
authored
Revert "Remove BottomNavigationBarItem.title deprecation" (flutter#91930)
1 parent 99c8dd5 commit 9608a64

File tree

6 files changed

+90
-71
lines changed

6 files changed

+90
-71
lines changed

packages/flutter/lib/src/cupertino/bottom_tab_bar.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
254254
Expanded(
255255
child: Center(child: active ? item.activeIcon : item.icon),
256256
),
257+
if (item.title != null) item.title!,
257258
if (item.label != null) Text(item.label!),
258259
];
259260
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ class BottomNavigationBar extends StatefulWidget {
185185
}) : assert(items != null),
186186
assert(items.length >= 2),
187187
assert(
188+
items.every((BottomNavigationBarItem item) => item.title != null) ||
188189
items.every((BottomNavigationBarItem item) => item.label != null),
189-
'Every item must have a non-null label',
190+
'Every item must have a non-null title or label',
190191
),
191192
assert(0 <= currentIndex && currentIndex < items.length),
192193
assert(elevation == null || elevation >= 0.0),
@@ -246,13 +247,13 @@ class BottomNavigationBar extends StatefulWidget {
246247
final double iconSize;
247248

248249
/// The color of the selected [BottomNavigationBarItem.icon] and
249-
/// [BottomNavigationBarItem.label].
250+
/// [BottomNavigationBarItem.title].
250251
///
251252
/// If null then the [ThemeData.primaryColor] is used.
252253
final Color? selectedItemColor;
253254

254255
/// The color of the unselected [BottomNavigationBarItem.icon] and
255-
/// [BottomNavigationBarItem.label]s.
256+
/// [BottomNavigationBarItem.title]s.
256257
///
257258
/// If null then the [ThemeData.unselectedWidgetColor]'s color is used.
258259
final Color? unselectedItemColor;
@@ -691,7 +692,7 @@ class _Label extends StatelessWidget {
691692
),
692693
),
693694
alignment: Alignment.bottomCenter,
694-
child: Text(item.label!),
695+
child: item.title ?? Text(item.label!),
695696
),
696697
);
697698

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class BottomNavigationBarThemeData with Diagnosticable {
7878
final IconThemeData? unselectedIconTheme;
7979

8080
/// The color of the selected [BottomNavigationBarItem.icon] and
81-
/// [BottomNavigationBarItem.label].
81+
/// [BottomNavigationBarItem.title].
8282
///
8383
/// See [BottomNavigationBar.selectedItemColor].
8484
final Color? selectedItemColor;
8585

8686
/// The color of the unselected [BottomNavigationBarItem.icon] and
87-
/// [BottomNavigationBarItem.label]s.
87+
/// [BottomNavigationBarItem.title]s.
8888
///
8989
/// See [BottomNavigationBar.unselectedItemColor].
9090
final Color? unselectedItemColor;

packages/flutter/lib/src/widgets/bottom_navigation_bar_item.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ class BottomNavigationBarItem {
2424
/// The argument [icon] should not be null and the argument [label] should not be null when used in a Material Design's [BottomNavigationBar].
2525
const BottomNavigationBarItem({
2626
required this.icon,
27+
@Deprecated(
28+
'Use "label" instead, as it allows for an improved text-scaling experience. '
29+
'This feature was deprecated after v1.19.0.',
30+
)
31+
this.title,
2732
this.label,
2833
Widget? activeIcon,
2934
this.backgroundColor,
3035
this.tooltip,
3136
}) : activeIcon = activeIcon ?? icon,
37+
assert(label == null || title == null),
3238
assert(icon != null);
3339

3440
/// The icon of the item.
@@ -61,6 +67,15 @@ class BottomNavigationBarItem {
6167
/// * [BottomNavigationBarItem.icon], for a description of how to pair icons.
6268
final Widget activeIcon;
6369

70+
/// The title of the item. If the title is not provided only the icon will be shown when not used in a Material Design [BottomNavigationBar].
71+
///
72+
/// This field is deprecated, use [label] instead.
73+
@Deprecated(
74+
'Use "label" instead, as it allows for an improved text-scaling experience. '
75+
'This feature was deprecated after v1.19.0.',
76+
)
77+
final Widget? title;
78+
6479
/// The text label for this [BottomNavigationBarItem].
6580
///
6681
/// This will be used to create a [Text] widget to put in the bottom navigation bar.

packages/flutter/test/cupertino/bottom_tab_bar_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ Future<void> main() async {
429429
semantics.dispose();
430430
});
431431

432-
testWidgets('Label of items should be nullable', (WidgetTester tester) async {
432+
testWidgets('Title of items should be nullable', (WidgetTester tester) async {
433433
final MemoryImage iconProvider = MemoryImage(Uint8List.fromList(kTransparentImage));
434434
final List<int> itemsTapped = <int>[];
435435

0 commit comments

Comments
 (0)