Skip to content

[material_ui] Add Checkbox.markInsets - #12690

Open
Munawer-Ali wants to merge 8 commits into
flutter:mainfrom
Munawer-Ali:checkbox-mark-insets
Open

Munawer-Ali wants to merge 8 commits into
flutter:mainfrom
Munawer-Ali:checkbox-mark-insets

Conversation

@Munawer-Ali

@Munawer-Ali Munawer-Ali commented Aug 30, 2026 •

Copy link
Copy Markdown

This PR ports my changes from flutter/flutter#188258 to
flutter/packages,
as part of flutter/flutter#188444

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, 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.markInsets defaults to null
  • Checkbox with no markInsets paints the check at full stroke width (backward-compat)
  • Checkbox.markInsets shrinks the check mark and its stroke
  • Checkbox.markInsets shrinks the indeterminate dash
  • Checkbox.markInsets larger than the box collapses the mark without crashing
  • Checkbox.markInsets falls back to CheckboxThemeData.markInsets
  • Checkbox.markInsets overrides CheckboxThemeData.markInsets

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: material_ui triage-design Should be looked at in design triage labels Aug 30, 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 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.

Comment on lines 118 to 119
}) : _checkboxType = _CheckboxType.material,
assert(tristate || value != null);

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

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.');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checkbox is a const constructor, so this suggestion won't compile. We should assert on the markInsets setter below instead.

Comment on lines 159 to 160
}) : _checkboxType = _CheckboxType.adaptive,
assert(tristate || value != null);

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

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.');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as above, Checkbox.adaptive is a const constructor, so this suggestion won't compile.

Comment on lines +740 to +746
set markInsets(EdgeInsets value) {
if (_markInsets == value) {
return;
}
_markInsets = value;
notifyListeners(); // triggers repaint when it changes
}

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

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
  }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Valid suggestion, but assert(value.isNonNegative, 'markInsets must be non-negative.') is more readable.

@elliette
elliette requested review from QuncCccccc and removed request for QuncCccccc September 1, 2026 21:32
@elliette

elliette commented Sep 1, 2026

Copy link
Copy Markdown
Member

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
elliette marked this pull request as draft September 1, 2026 21:32
@Munawer-Ali
Munawer-Ali marked this pull request as ready for review September 2, 2026 05:55
@Munawer-Ali

Copy link
Copy Markdown
Author

@elliette Thanks! I've added the Pre-Review Checklist to the description and completed the steps.
Marking as ready for review.

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

Comment thread packages/material_ui/lib/src/checkbox.dart
Comment thread packages/material_ui/lib/src/checkbox.dart
Comment thread packages/material_ui/lib/src/checkbox_theme.dart
Comment thread packages/material_ui/test/checkbox_test.dart

@QuncCccccc QuncCccccc 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.

LGTM. Thank you for helping port over the fix!

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Sep 2, 2026
@QuncCccccc
QuncCccccc requested a review from elliette September 2, 2026 21:37
@elliette elliette added CICD Run CI/CD and removed CICD Run CI/CD labels Sep 2, 2026
/// {@endtemplate}
final String? semanticLabel;

/// {@template flutter.material.checkbox.markInsets}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a new line at the end of this file

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 4, 2026
@Munawer-Ali

Copy link
Copy Markdown
Author

Thanks for the review @elliette Updated the dartdoc template and macro to
material_ui.checkbox.markInsets in both files, and added the trailing newline
to the changelog file.

@Munawer-Ali

Copy link
Copy Markdown
Author

@QuncCccccc Hi Ma’am, could you please review and approve the changes in this PR when you have a chance? Thank you!

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Sep 10, 2026

@QuncCccccc QuncCccccc 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.

LGTM. Thanks!

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 12, 2026
@Munawer-Ali

Copy link
Copy Markdown
Author

Hi @elliette , could you please take a look at this PR when you get a chance?

@Munawer-Ali

Copy link
Copy Markdown
Author

@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! 🙏

Comment on lines 118 to 119
}) : _checkboxType = _CheckboxType.material,
assert(tristate || value != null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checkbox is a const constructor, so this suggestion won't compile. We should assert on the markInsets setter below instead.

Comment on lines 159 to 160
}) : _checkboxType = _CheckboxType.adaptive,
assert(tristate || value != null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as above, Checkbox.adaptive is a const constructor, so this suggestion won't compile.

Comment on lines +740 to +746
set markInsets(EdgeInsets value) {
if (_markInsets == value) {
return;
}
_markInsets = value;
notifyListeners(); // triggers repaint when it changes
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"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)).

@Munawer-Ali

Copy link
Copy Markdown
Author

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
proportional with EdgeInsets.all. With something like only(left: 9) the code was
shrinking the width but not the height, so the check came out squashed. My docs were
wrong about that.

Fixed it so both axes use the same scale and the mark sits centered in whatever space
is left. The dash had the same problem. Symmetric insets look exactly like before, so
none of the old tests changed.

Added tests for only(left:), only(top:), only(right:) and symmetric(horizontal:), plus
one for the dash.

@Munawer-Ali

Copy link
Copy Markdown
Author

@QuncCccccc Sorry to bother you again, but could you please ask @elliette to review it again when they have a chance?

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Sep 30, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 30, 2026
@elliette elliette added the CICD Run CI/CD label Sep 30, 2026

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! One more suggestion otherwise looks good

final BorderSide? side;

/// {@macro material_ui.checkbox.markInsets}
final EdgeInsets? markInsets;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a padding property to Checkbox widget ✅ around check icon ✔.

3 participants