[cupertino_ui] Remove two items assert to allow CupertinoTabBar to have one tab - #12546
Open
Wreos wants to merge 1 commit into
Open
[cupertino_ui] Remove two items assert to allow CupertinoTabBar to have one tab#12546Wreos wants to merge 1 commit into
Wreos wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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.'), |
Contributor
There was a problem hiding this comment.
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
- Effective Dart recommends using
isEmptyandisNotEmptyrather than checking length against 0. (link)
Author
There was a problem hiding this comment.
Unfortunately it is not applicable in this case
CupertinoTabBar has a const constructor and items. isNotEmpty is not a valid constant expression.
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on discussion
Removed assert to enable CupertinoTabBar to support 1 tab and updated the test.
Fixes #42430
Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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