Skip to content

Commit 9f595f3

Browse files
authored
[cupertino_ui] Remove two items assert to allow CupertinoTabBar to have one tab (#12546)
Based on [discussion](flutter/flutter#42430 (comment)) Removed assert to enable CupertinoTabBar to support 1 tab and updated the test. Fixes [#42430](flutter/flutter#42430) ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 4fc3e81 commit 9f595f3

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎packages/cupertino_ui/lib/src/bottom_tab_bar.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
8181
width: 0.0, // 0.0 means one physical pixel
8282
),
8383
),
84-
}) : assert(items.length >= 2, "Tabs need at least 2 items to conform to Apple's HIG"),
84+
}) : assert(items.length > 0, 'CupertinoTabBar requires at least one tab.'),
8585
assert(0 <= currentIndex && currentIndex < items.length),
8686
assert(height >= 0.0);
8787

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Allows `CupertinoTabBar` to contain a single item.
3+
version: patch

‎packages/cupertino_ui/test/bottom_tab_bar_test.dart‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,32 @@ Future<void> pumpWidgetWithBoilerplate(WidgetTester tester, Widget widget) async
2222
}
2323

2424
Future<void> main() async {
25-
testWidgets('Need at least 2 tabs', (WidgetTester tester) async {
26-
await expectLater(
27-
() => pumpWidgetWithBoilerplate(
28-
tester,
29-
CupertinoTabBar(
30-
items: const <BottomNavigationBarItem>[
31-
BottomNavigationBarItem(icon: Icon(CupertinoIcons.search), label: 'Tab 1'),
32-
],
33-
),
34-
),
25+
test('CupertinoTabBar requires at least one item', () {
26+
expect(
27+
() => CupertinoTabBar(items: const <BottomNavigationBarItem>[]),
3528
throwsA(
3629
isAssertionError.having(
3730
(AssertionError error) => error.toString(),
3831
'.toString()',
39-
contains('items.length'),
32+
contains('CupertinoTabBar requires at least one tab.'),
4033
),
4134
),
4235
);
4336
});
4437

38+
testWidgets('CupertinoTabBar supports one item', (WidgetTester tester) async {
39+
await pumpWidgetWithBoilerplate(
40+
tester,
41+
CupertinoTabBar(
42+
items: const <BottomNavigationBarItem>[
43+
BottomNavigationBarItem(icon: Icon(CupertinoIcons.search), label: 'Tab 1'),
44+
],
45+
),
46+
);
47+
48+
expect(find.byType(CupertinoTabBar), findsOneWidget);
49+
});
50+
4551
testWidgets('Active and inactive colors', (WidgetTester tester) async {
4652
await pumpWidgetWithBoilerplate(
4753
tester,

0 commit comments

Comments
 (0)