Repository navigation
TextStyle.lerp() does not properly interpolate text shadows #145665
Description
Steps to reproduce
-
Create two
TextStyleinstances with differentshadowslists. For example:final style1 = TextStyle( fontSize: 24, shadows: [ Shadow( blurRadius: 10, color: Colors.blue, offset: Offset(0, 0), ), ], ); final style2 = TextStyle( fontSize: 24, shadows: [ Shadow( blurRadius: 20, color: Colors.red, offset: Offset(5, 5), ), ], );
-
Use
TextStyle.lerp()to interpolate between the two styles with an interpolation factor (t) of your choice. For example:final interpolatedStyle = TextStyle.lerp(style1, style2, 0.5);
-
Observe that the resulting
interpolatedStyledoes not have smoothly interpolated shadow properties. Instead, it will abruptly switch between theshadowslists ofstyle1andstyle2based on the value oft. -
Vary the interpolation factor (
t) and notice that the text shadows do not gradually transition between the two styles. They will instantly change from one set of shadows to another at the midpoint of the interpolation. -
To see this behavior in action, you can use
TextStyle.lerp()within an animation or a widget that animates the interpolation factor over time, such asAnimatedDefaultTextStyleorAnimatedBuilder. Observe that the text shadows do not smoothly animate between the two styles and instead abruptly switch at the midpoint of the animation.
Expected results
When interpolating between two TextStyle instances using TextStyle.lerp(), the shadows property should be smoothly interpolated based on the provided interpolation factor (t). This can be adjusted by using ui.Shadow.listLerp() as part
Each shadow's blurRadius, color, and offset should be linearly combined from the corresponding values in the input styles.
POC example: https://dartpad.dev/?id=799c4bec8b791b74580193174759b93d
Actual results
TextStyle.lerp() does not correctly interpolate the shadows property between two TextStyle instances.
Instead of smoothly transitioning each shadow's blurRadius, color, and offset based on the interpolation factor (t), it abruptly switches between the entire shadows lists at the midpoint of the interpolation.
This results in a visually inconsistent and jarring transition of text shadows, not meeting the expected smooth interpolation behavior.
Code sample
https://dartpad.dev/?id=08ea4c1134faccc09935c84eeac85322
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
N/A
Activity
danagbemava-nc commentedon Mar 25, 2024
Reproducible using the code sample provided above.
Screen.Recording.2024-03-25.at.11.20.31.mov
sample (from dartpad above)
flutter doctor -v
Fix TextStyle.lerp() to properly interpolate text shadows (#145666)
github-actions commentedon Apr 18, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.