For ShapeBorder instances with preferPaintInterior=true, use paintInterior rather than drawing the path from getOuterPath.#184258
Conversation
…erior rather than drawing the path from getOuterPath.
There was a problem hiding this comment.
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.
| if (avatarBorder!.preferPaintInterior) { | ||
| avatarBorder!.paintInterior(context.canvas, avatarRect, darkenPaint); | ||
| } else { | ||
| final Path path = avatarBorder!.getOuterPath(avatarRect); | ||
| context.canvas.drawPath(path, darkenPaint); | ||
| } |
There was a problem hiding this comment.
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);
}| if (shape!.preferPaintInterior) { | ||
| shape!.paintInterior(canvas, _thumbRect!, _paintThumb); | ||
| } else { | ||
| final Path outerPath = shape!.getOuterPath(_thumbRect!); | ||
| canvas.drawPath(outerPath, _paintThumb); | ||
| } | ||
| shape!.paint(canvas, _thumbRect!); |
There was a problem hiding this comment.
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);
gaaclarke
left a comment
There was a problem hiding this comment.
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.
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…e paintInterior rather than drawing the path from getOuterPath. (flutter/flutter#184258)
…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
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:
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-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.