Skip to content

[cupertino_ui] Remove two items assert to allow CupertinoTabBar to have one tab - #12546

Open
Wreos wants to merge 1 commit into
flutter:mainfrom
Wreos:fix/cupertino-tab-bar-single-item
Open

[cupertino_ui] Remove two items assert to allow CupertinoTabBar to have one tab#12546
Wreos wants to merge 1 commit into
flutter:mainfrom
Wreos:fix/cupertino-tab-bar-single-item

Conversation

@Wreos

@Wreos Wreos commented Aug 22, 2026

Copy link
Copy Markdown

Based on discussion
Removed assert to enable CupertinoTabBar to support 1 tab and updated the test.

Fixes #42430

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. 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.

Footnotes

  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. 2

@github-actions github-actions Bot added p: cupertino_ui triage-design Should be looked at in design triage labels Aug 22, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates CupertinoTabBar to allow a single item by changing the assertion from requiring at least two items to requiring at least one, and updates the associated tests and changelog. Feedback suggests using isNotEmpty instead of checking length > 0 on the collection, in line with Effective Dart guidelines.

),
),
}) : assert(items.length >= 2, "Tabs need at least 2 items to conform to Apple's HIG"),
}) : assert(items.length > 0, 'CupertinoTabBar requires at least one tab.'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Following the Effective Dart guidelines, it is preferred to use isNotEmpty instead of checking length > 0 on collections.

  }) : assert(items.isNotEmpty, 'CupertinoTabBar requires at least one tab.'),
References
  1. Effective Dart recommends using isEmpty and isNotEmpty rather than checking length against 0. (link)

@Wreos Wreos Aug 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it is not applicable in this case
CupertinoTabBar has a const constructor and items. isNotEmpty is not a valid constant expression.

@Wreos Wreos changed the title Remove two items assert to allow CupertinoTabBar to have one tab [cupertino_ui] Remove two items assert to allow CupertinoTabBar to have one tab Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: cupertino_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove an assertion from CupertinoTabBar widget

1 participant