Skip to content

For ShapeBorder instances with preferPaintInterior=true, use paintInterior rather than drawing the path from getOuterPath.#184258

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
b-luk:paintinterior
Mar 28, 2026
Merged

For ShapeBorder instances with preferPaintInterior=true, use paintInterior rather than drawing the path from getOuterPath.#184258
auto-submit[bot] merged 3 commits into
flutter:masterfrom
b-luk:paintinterior

Conversation

@b-luk

@b-luk b-luk commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

For ShapeBorder instances with preferPaintInterior=true, use paintInterior rather than drawing the path from getOuterPath.

From https://api.flutter.dev/flutter/painting/ShapeBorder/paintInterior.html:

On ShapeBorder subclasses whose preferPaintInterior method returns true, this should be faster than using Canvas.drawPath with the path provided by getOuterPath.

paintInterior is semantically equivalent to (i.e. renders the same pixels as) calling Canvas.drawPath with the same Paint and the Path returned from getOuterPath

Part of #183044

Pre-launch 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.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. f: cupertino flutter/packages/flutter/cupertino repository labels Mar 27, 2026
…erior rather than drawing the path from getOuterPath.
@b-luk b-luk added the CICD Run CI/CD label Mar 27, 2026
@b-luk b-luk changed the title For ShapeBorder instances that set preferPaintInterior, use paintInterior rather than drawing the path from getOuterPath. For ShapeBorder instances with preferPaintInterior=true, use paintInterior rather than drawing the path from getOuterPath. Mar 27, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 27, 2026
@b-luk b-luk added the CICD Run CI/CD label Mar 27, 2026
@github-actions github-actions Bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos and removed CICD Run CI/CD labels Mar 27, 2026
@b-luk b-luk added the CICD Run CI/CD label Mar 27, 2026
@b-luk b-luk marked this pull request as ready for review March 27, 2026 22:44

@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 the painting logic for several widgets, including Checkbox, Chip, InputDecorator, and Scrollbar, to utilize the preferPaintInterior and paintInterior methods of ShapeBorder. This allows for more efficient painting by using specific primitives like rounded rectangles or circles instead of generic paths when supported by the shape. Numerous tests were updated to reflect these changes in the painting commands. The review feedback suggests refactoring code in chip.dart and scrollbar.dart to use local variables for non-nullable types, thereby avoiding repeated null assertions.

Comment on lines +2181 to +2186
if (avatarBorder!.preferPaintInterior) {
avatarBorder!.paintInterior(context.canvas, avatarRect, darkenPaint);
} else {
final Path path = avatarBorder!.getOuterPath(avatarRect);
context.canvas.drawPath(path, darkenPaint);
}

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 improve readability and avoid repeated null assertions (!), you could introduce a local variable for avatarBorder after the null check. This makes the code cleaner and safer.

final ShapeBorder localAvatarBorder = avatarBorder!;
if (localAvatarBorder.preferPaintInterior) {
  localAvatarBorder.paintInterior(context.canvas, avatarRect, darkenPaint);
} else {
  final Path path = localAvatarBorder.getOuterPath(avatarRect);
  context.canvas.drawPath(path, darkenPaint);
}

Comment on lines +642 to 648
if (shape!.preferPaintInterior) {
shape!.paintInterior(canvas, _thumbRect!, _paintThumb);
} else {
final Path outerPath = shape!.getOuterPath(_thumbRect!);
canvas.drawPath(outerPath, _paintThumb);
}
shape!.paint(canvas, _thumbRect!);

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 improve readability and avoid repeated null assertions (!), you could introduce local variables for shape and _thumbRect. This makes the code cleaner and safer.

final ShapeBorder localShape = shape!;
final Rect thumbRect = _thumbRect!;
if (localShape.preferPaintInterior) {
  localShape.paintInterior(canvas, thumbRect, _paintThumb);
} else {
  final Path outerPath = localShape.getOuterPath(thumbRect);
  canvas.drawPath(outerPath, _paintThumb);
}
localShape.paint(canvas, thumbRect);

@b-luk b-luk requested a review from gaaclarke March 27, 2026 23:35

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

Oh nice. I was worried as I read through the PR about testing but looks like we had nice coverage to make sure we don't accidentally break this in the future. Thanks.

@b-luk b-luk added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Mar 28, 2026
Merged via the queue into flutter:master with commit bfe5141 Mar 28, 2026
79 of 80 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 28, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
@b-luk b-luk deleted the paintinterior branch March 30, 2026 16:28
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2026
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…erior rather than drawing the path from getOuterPath. (flutter#184258)

For ShapeBorder instances with preferPaintInterior=true, use
paintInterior rather than drawing the path from getOuterPath.

From
https://api.flutter.dev/flutter/painting/ShapeBorder/paintInterior.html:
> On
[ShapeBorder](https://api.flutter.dev/flutter/painting/ShapeBorder-class.html)
subclasses whose
[preferPaintInterior](https://api.flutter.dev/flutter/painting/ShapeBorder/preferPaintInterior.html)
method returns true, this should be faster than using
[Canvas.drawPath](https://api.flutter.dev/flutter/dart-ui/Canvas/drawPath.html)
with the path provided by
[getOuterPath](https://api.flutter.dev/flutter/painting/ShapeBorder/getOuterPath.html).

>
[paintInterior](https://api.flutter.dev/flutter/painting/ShapeBorder/paintInterior.html)
is semantically equivalent to (i.e. renders the same pixels as) calling
[Canvas.drawPath](https://api.flutter.dev/flutter/dart-ui/Canvas/drawPath.html)
with the same
[Paint](https://api.flutter.dev/flutter/dart-ui/Paint-class.html) and
the [Path](https://api.flutter.dev/flutter/dart-ui/Path-class.html)
returned from
[getOuterPath](https://api.flutter.dev/flutter/painting/ShapeBorder/getOuterPath.html)

Part of flutter#183044

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

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](https://developers.google.com/gemini-code-assist/docs/review-github-code).
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.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants