Repository navigation
Conversation
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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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".
|
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. |
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-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.