Skip to content

Add padding property to Checkbox#188258

Open
Munawer-Ali wants to merge 3 commits into
flutter:masterfrom
Munawer-Ali:checkbox-padding
Open

Add padding property to Checkbox#188258
Munawer-Ali wants to merge 3 commits into
flutter:masterfrom
Munawer-Ali:checkbox-padding

Conversation

@Munawer-Ali

Copy link
Copy Markdown

This PR adds an optional padding property to the Checkbox widget.
Currently the check mark always fills the entire checkbox box, with no way to add space between the mark and the box edges (see #188031). This adds a padding field (EdgeInsetsGeometry?) that insets the check mark — and the indeterminate dash — inside the box.

Fixes
Fixes flutter/flutter#188031

Tests

Added to test/material/checkbox_test.dart:

  • Checkbox.padding defaults to null
  • Checkbox with no padding paints at full stroke width (backward-compat)
  • Checkbox.padding shrinks the check mark and its stroke
  • Checkbox.padding shrinks the indeterminate dash
  • Checkbox.padding larger than the box collapses the mark without crashing
  • Checkbox asserts when padding is negative

Pre-launch Checklist

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

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

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.

@google-cla

google-cla Bot commented Jun 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jun 19, 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 adds a padding property to the Checkbox widget, which insets and proportionally scales the check mark and indeterminate dash. The review feedback suggests documenting that this padding is ignored on iOS and macOS when using Checkbox.adaptive, adding padding to CheckboxThemeData for global styling, correcting the documentation regarding its default value, and exposing the property in debugFillProperties for debugging.

this.side,
this.isError = false,
this.semanticLabel,
this.padding,

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 Checkbox.adaptive delegates to CupertinoCheckbox on iOS and macOS, and CupertinoCheckbox does not currently support a padding property, this padding will be ignored on those platforms. Please document this platform-specific behavior in the padding property's API documentation or the Checkbox.adaptive constructor documentation so developers are aware of this limitation.

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.

The documentation update regarding the platform-specific behavior of Checkbox.adaptive is appreciated. I noticed a small issue in packages/flutter/lib/src/material/checkbox_theme.dart: there is a duplicate line in debugFillProperties where side is added twice. Please remove the redundant line.

Suggested change
this.padding,
properties.add(DiagnosticsProperty<BorderSide>('side', side, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null));

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.

/gemini review

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.

The code changes in this pull request correctly implement the padding property for the Checkbox widget. The implementation properly handles the resolvedPadding against the ambient Directionality, updates the _CheckboxPainter to use the padding for the check mark and indeterminate dash, and includes comprehensive tests covering edge cases and theme interactions. The documentation also correctly addresses the platform-specific limitation for Checkbox.adaptive on iOS and macOS. The redundant line in debugFillProperties has been removed as requested.

/// {@endtemplate}
final String? semanticLabel;

/// The padding around the check mark when the checkbox is checked or

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 support global styling and consistent theming across the application, the padding property should also be added to CheckboxThemeData in checkbox_theme.dart and resolved here (e.g., widget.padding ?? checkboxTheme.padding ?? EdgeInsets.zero).

Comment on lines +419 to +421
/// Defaults to [EdgeInsets.zero], which renders the check mark at its full
/// size (the same as before this property existed).
final EdgeInsetsGeometry? padding;

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

The documentation states Defaults to [EdgeInsets.zero], but the actual property value defaults to null (which is then resolved to EdgeInsets.zero internally). To be precise and follow Flutter's documentation standards, please clarify this.

For example:
Defaults to null, which resolves to [EdgeInsets.zero].

  /// Defaults to null, which resolves to [EdgeInsets.zero], rendering the
  /// check mark at its full size (the same as before this property existed).
  final EdgeInsetsGeometry? padding;

Comment thread packages/flutter/lib/src/material/checkbox.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant