Skip to content

Add RenderSliver.getMaxPaintRect#180074

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
zemanux:get_max_paint_rect
Jan 21, 2026
Merged

Add RenderSliver.getMaxPaintRect#180074
auto-submit[bot] merged 2 commits into
flutter:masterfrom
zemanux:get_max_paint_rect

Conversation

@zemanux

@zemanux zemanux commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

This PR extracts the getMaxPaintRect logic into a shared method in RenderSliver. This helper is required for upcoming changes in #179003 and #179802 to avoid code duplication.

Cc @Piinks

Pre-launch Checklist

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

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Dec 18, 2025

@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 extracts a shared method RenderSliver.getMaxPaintRect and adds comprehensive tests for it. The implementation appears correct and the tests cover various scenarios. I have one suggestion to improve code style and readability by renaming a local variable to avoid shadowing an instance member.

Comment thread packages/flutter/lib/src/rendering/sliver.dart Outdated
@protected
Rect getMaxPaintRect() {
final SliverGeometry? sliverGeometry = geometry;
if (sliverGeometry == 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.

Suggested change
if (sliverGeometry == null) {
if (sliverGeometry == null || sliverGeometry == SliverGeometry.zero) {

Should we short circuit the zero case here as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes!

constraints.scrollOffset + sliverGeometry.cacheExtent + constraints.cacheOrigin;
}
final double paintExtent = sliverGeometry.paintExtent;
// If sliver is pinned, the scroll offset is sticked to the edge.

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.

Suggested change
// If sliver is pinned, the scroll offset is sticked to the edge.
// If sliver is pinned, the scroll offset is stuck to the edge.

I think? Can you explain this a bit more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.
I've tried to make it clearer. I also renamed the variable to leadingOffset.

-clampedScrollOffset,
0.0,
maxPaintExtent,
constraints.crossAxisExtent,

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.

Could this potentially be incorrect in the case of SliverCrossAxisGroup? The rect may not go from 0 --> crossAxisExtent if there are multiple slivers in the cross axis grouping.

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.

This would make for some good test cases as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could this potentially be incorrect in the case of SliverCrossAxisGroup? The rect may not go from 0 --> crossAxisExtent if there are multiple slivers in the cross axis grouping.

This is a good catch! Done!

sliver.layout(
const SliverConstraints(
axisDirection: AxisDirection.down,
growthDirection: GrowthDirection.forward,

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.

Should there be test cases that cover when GrowthDirection.reverse is used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
}

/// Returns the [Rect] that covers the total paint extent of the sliver.

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.

I might add to the docs clarity about what coordinate space this rect is, local to the viewport, global to the screen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I might add to the docs clarity about what coordinate space this rect is, local to the viewport, global to the screen?

Done. Let me know if that's okay.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, the resulting coordinates match the ones used in paint (via the offset parameter). So I tried to use the same terminology in the explanation.

@zemanux zemanux force-pushed the get_max_paint_rect branch from 8fad906 to 58c2388 Compare January 8, 2026 12:04
@justinmc justinmc requested a review from Piinks January 13, 2026 23:17

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

This LGTM! Thank you!

@Renzo-Olivares Renzo-Olivares 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 your patience and contribution!

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 20, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 20, 2026
@auto-submit

auto-submit Bot commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/180074, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@Piinks

Piinks commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Rebasing to pass the check. :)

@Piinks Piinks force-pushed the get_max_paint_rect branch from 986357d to 084e702 Compare January 20, 2026 23:40
@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 20, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jan 21, 2026
Merged via the queue into flutter:master with commit d20a814 Jan 21, 2026
71 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 21, 2026
@zemanux zemanux deleted the get_max_paint_rect branch January 21, 2026 06:41
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 23, 2026
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
This PR extracts the `getMaxPaintRect` logic into a shared method in
`RenderSliver`. This helper is required for upcoming changes in flutter#179003
and flutter#179802 to avoid code duplication.

Cc @Piinks 

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants