Skip to content

Keep backgroundBlendMode in BoxDecoration.lerp and scale - #195226

Open
Crdzbird wants to merge 2 commits into
flutter:masterfrom
Crdzbird:fix-box-decoration-blend-mode-lerp
Open

Crdzbird wants to merge 2 commits into
flutter:masterfrom
Crdzbird:fix-box-decoration-blend-mode-lerp

Conversation

@Crdzbird

@Crdzbird Crdzbird commented Oct 24, 2026 •

Copy link
Copy Markdown

BoxDecoration.lerp and BoxDecoration.scale did not pass backgroundBlendMode to the new decoration, so AnimatedContainer painted the frames in between with the default blend mode and the box flickered.

scale now keeps the blend mode. lerp uses the blend mode of a below t = 0.5 and of b from there on, same as shape.

Fixes #164778

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.

BoxDecoration.lerp and BoxDecoration.scale built the new decoration without
backgroundBlendMode, so every intermediate frame of an implicit animation such
as AnimatedContainer was painted with the default blend mode.

Fixes flutter#164778
@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 24, 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 updates BoxDecoration to support backgroundBlendMode during scaling and interpolation. Specifically, BoxDecoration.scale now preserves the backgroundBlendMode, and BoxDecoration.lerp switches the backgroundBlendMode at t = 0.5. Relevant documentation and unit tests have been added to verify these behaviors. I have no feedback to provide.

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked the null-dispatch paths before the new ternary: lerp returns via b!.scale(t) / a.scale(1.0 - t) whenever either side is null, so t < 0.5 ? a.backgroundBlendMode : b.backgroundBlendMode only runs with both decorations non-null — no NPE risk there, and the one-sided cases now inherit the mode through scale, which the test at t=0.5 with a null side exercises. == and hashCode already include the field, so the newly-preserved mode participates in decoration equality correctly.

Matching the shape: t < 0.5 ? a.shape : b.shape precedent is the right call — there's no meaningful interpolation between two discrete blend modes, and for the animated case that motivated this (same blend mode on both endpoints, as in #164778) the mode is now carried continuously instead of dropping to null mid-animation.

One consequence worth being aware of (not a request to change anything): with different modes on the two endpoints, the mode now pops from a's to b's exactly at t = 0.5 mid-animation, where previously it popped to null at the animation's very first lerped frame and stayed there. That's a visible pop either way — consistent with how shape already behaves, just noting the failure mode moved from "always wrong" to "wrong at one instant".

@Crdzbird

Copy link
Copy Markdown
Author

Thanks for checking. Yes, with different modes on the two ends it switches at t = 0.5, same as shape, since two blend modes can't be interpolated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnimatedContainer not properly animating BoxDecoration with backgroundBlendMode: BlendMode.overlay

2 participants