[material_ui] Add Checkbox.markInsets - #12690
Munawer-Ali wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces 'markInsets' to 'Checkbox' and 'CheckboxThemeData' to allow insetting the check mark and indeterminate dash within the checkbox, shrinking them proportionally without altering the overall box size. The feedback suggests adding assertions in the 'Checkbox' constructors and the '_CheckboxPainter' setter to enforce that 'markInsets' is non-negative, as specified in the documentation.
| }) : _checkboxType = _CheckboxType.material, | ||
| assert(tristate || value != null); |
There was a problem hiding this comment.
Since the documentation for markInsets states that it "Must be non-negative", we should enforce this constraint with an assertion in the constructor to catch invalid values early in development.
}) : _checkboxType = _CheckboxType.material,
assert(tristate || value != null),
assert(markInsets == null || (markInsets.left >= 0.0 && markInsets.top >= 0.0 && markInsets.right >= 0.0 && markInsets.bottom >= 0.0), 'markInsets must be non-negative.');There was a problem hiding this comment.
Checkbox is a const constructor, so this suggestion won't compile. We should assert on the markInsets setter below instead.
| }) : _checkboxType = _CheckboxType.adaptive, | ||
| assert(tristate || value != null); |
There was a problem hiding this comment.
Similarly, we should add the non-negative assertion for markInsets in the Checkbox.adaptive constructor.
}) : _checkboxType = _CheckboxType.adaptive,
assert(tristate || value != null),
assert(markInsets == null || (markInsets.left >= 0.0 && markInsets.top >= 0.0 && markInsets.right >= 0.0 && markInsets.bottom >= 0.0), 'markInsets must be non-negative.');There was a problem hiding this comment.
Same comment as above, Checkbox.adaptive is a const constructor, so this suggestion won't compile.
| set markInsets(EdgeInsets value) { | ||
| if (_markInsets == value) { | ||
| return; | ||
| } | ||
| _markInsets = value; | ||
| notifyListeners(); // triggers repaint when it changes | ||
| } |
There was a problem hiding this comment.
To ensure that invalid negative insets provided via CheckboxThemeData (which doesn't have constructor assertions) are also caught before they cause rendering anomalies, we should add an assertion in the _CheckboxPainter.markInsets setter.
set markInsets(EdgeInsets value) {
if (_markInsets == value) {
return;
}
assert(value.left >= 0.0 && value.top >= 0.0 && value.right >= 0.0 && value.bottom >= 0.0, 'markInsets must be non-negative.');
_markInsets = value;
notifyListeners(); // triggers repaint when it changes
}There was a problem hiding this comment.
Valid suggestion, but assert(value.isNonNegative, 'markInsets must be non-negative.') is more readable.
|
Thank you for your contribution! Because of the volume of PRs we receive, we require that new contributors use our checklist to guide them through critical steps in creating a Flutter PR. This PR's description is missing that checklist, so it is being marked as a Draft. Please edit the PR description to add the checklist, then ensure that you have completed all of the steps. Once you've done that, please mark the PR as ready for review. If you need help, consider asking for advice on the #hackers-new channel on Discord. |
|
@elliette Thanks! I've added the Pre-Review Checklist to the description and completed the steps. |
There was a problem hiding this comment.
Code Review
This pull request introduces markInsets to Checkbox and CheckboxThemeData, allowing the check mark and indeterminate dash to be inset and scaled proportionally within the checkbox. The reviewer recommends adding assertions to the Checkbox, Checkbox.adaptive, and CheckboxThemeData constructors to enforce that markInsets values are non-negative, along with a corresponding unit test to verify this validation.
QuncCccccc
left a comment
There was a problem hiding this comment.
LGTM. Thank you for helping port over the fix!
| /// {@endtemplate} | ||
| final String? semanticLabel; | ||
|
|
||
| /// {@template flutter.material.checkbox.markInsets} |
There was a problem hiding this comment.
This should be {@template material_ui.checkbox.markInsets} now :)
| /// If specified, overrides the default value of [Checkbox.side]. | ||
| final BorderSide? side; | ||
|
|
||
| /// {@macro flutter.material.checkbox.markInsets} |
There was a problem hiding this comment.
Also here {@macro material_ui.checkbox.markInsets}
| - Adds `Checkbox.markInsets` and `CheckboxThemeData.markInsets`, which inset the | ||
| check mark (and the indeterminate dash) within the checkbox without changing the | ||
| size of the box itself. The mark and its stroke shrink proportionally. | ||
| version: minor No newline at end of file |
There was a problem hiding this comment.
Please add a new line at the end of this file
|
Thanks for the review @elliette Updated the dartdoc template and macro to |
|
@QuncCccccc Hi Ma’am, could you please review and approve the changes in this PR when you have a chance? Thank you! |
|
Hi @elliette , could you please take a look at this PR when you get a chance? |
|
@QuncCccccc Sorry to disturb you again, Ma’am. Could you please ask @elliette to review this PR as well when you get a chance? Thank you so much for your support! 🙏 |
| }) : _checkboxType = _CheckboxType.material, | ||
| assert(tristate || value != null); |
There was a problem hiding this comment.
Checkbox is a const constructor, so this suggestion won't compile. We should assert on the markInsets setter below instead.
| }) : _checkboxType = _CheckboxType.adaptive, | ||
| assert(tristate || value != null); |
There was a problem hiding this comment.
Same comment as above, Checkbox.adaptive is a const constructor, so this suggestion won't compile.
| set markInsets(EdgeInsets value) { | ||
| if (_markInsets == value) { | ||
| return; | ||
| } | ||
| _markInsets = value; | ||
| notifyListeners(); // triggers repaint when it changes | ||
| } |
There was a problem hiding this comment.
Valid suggestion, but assert(value.isNonNegative, 'markInsets must be non-negative.') is more readable.
| /// | ||
| /// This insets the check mark inward; the size of the checkbox box itself | ||
| /// is not affected. The check mark and its stroke shrink to fit the | ||
| /// remaining space, so the mark stays proportional. |
There was a problem hiding this comment.
"so the mark stays proportional"
Please add some test cases to confirm this - currently they are all using EdgeInsets.all (e.g. test with EdgeInsets.only(left: 9)).
|
Thanks @elliette Moved the assert to the setter like you said The asymmetric tests were a good call, because they failed. Turns out the mark was only Fixed it so both axes use the same scale and the mark sits centered in whatever space Added tests for only(left:), only(top:), only(right:) and symmetric(horizontal:), plus |
|
@QuncCccccc Sorry to bother you again, but could you please ask @elliette to review it again when they have a chance? |
elliette
left a comment
There was a problem hiding this comment.
Thanks! One more suggestion otherwise looks good
| final BorderSide? side; | ||
|
|
||
| /// {@macro material_ui.checkbox.markInsets} | ||
| final EdgeInsets? markInsets; |
There was a problem hiding this comment.
Could you add markInsets to the existing tests in test/checkbox_theme_test.dart? copyWith, lerp, == and debugFillProperties now handle it, but nothing covers those paths. The "CheckboxThemeData implements debugFillProperties", "lerp with null parameters" and "lerp from populated to null parameters" tests are good places to add it.
This PR ports my changes from flutter/flutter#188258 to
flutter/packages,
as part of flutter/flutter#188444
Adds
Checkbox.markInsetsandCheckboxThemeData.markInsets, which inset the checkmark and the
indeterminate dash within the checkbox without changing the size of the box itself. The
mark and its
stroke shrink proportionally, and the mark is not painted if the insets leave no room.
Fixes flutter/flutter#188031
Tests
Added to
packages/material_ui/test/checkbox_test.dart:Checkbox.markInsetsdefaults to nullmarkInsetspaints the check at full stroke width (backward-compat)Checkbox.markInsetsshrinks the check mark and its strokeCheckbox.markInsetsshrinks the indeterminate dashCheckbox.markInsetslarger than the box collapses the mark without crashingCheckbox.markInsetsfalls back toCheckboxThemeData.markInsetsCheckbox.markInsetsoverridesCheckboxThemeData.markInsetsPre-Review Checklist
submitting PRs.
am not using AI tools.
brackets, e.g.
[shared_preferences]and the repository CHANGELOG style, or I have commented below to indicate which
documented exception this PR falls under1.
///).indicate which test exemption this PR falls under1.
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