Skip to content

TextStyle.lerp() does not properly interpolate text shadows #145665

@leoafarias

Description

@leoafarias

Steps to reproduce

  1. Create two TextStyle instances with different shadows lists. 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),
        ),
      ],
    );
  2. 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);
  3. Observe that the resulting interpolatedStyle does not have smoothly interpolated shadow properties. Instead, it will abruptly switch between the shadows lists of style1 and style2 based on the value of t.

  4. 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.

  5. 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 as AnimatedDefaultTextStyle or AnimatedBuilder. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsfound in release: 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions