Skip to content

TextStyle.lerp fades backgroundColor in when interpolating to null #196151

Closed

Description

@hangy233

Steps to reproduce

  1. Create an app with Flutter 3.47.9.
  2. Define one TextStyle whose background is opaque red.
  3. Render that style on three text rows using TextStyle.lerp(redStyle, null, t). Set t to 0, 0.5, and 1 respectively, and label each row with its value. These rows represent the start, midpoint, and end of a transition from the red style toward null.
  4. Run the app with flutter run -d chrome and compare the red background behind each row.

Additional context

In the b == null branch, TextStyle.lerp currently uses Color.lerp(null, a.backgroundColor, t), reversing the fade direction. The adjacent color and decorationColor fields interpolate from their value toward null. A regression test fails on unchanged 3.47.9 and passes when the backgroundColor arguments are reversed. The proposed fix is in this commit.

Expected results

The background fades out: opaque red at t = 0, half transparent at t = 0.5, and transparent at t = 1.

Actual results

The background fades in: transparent at t = 0, half transparent at t = 0.5, and opaque red at t = 1.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  const redStyle = TextStyle(backgroundColor: Colors.red);

  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            for (final t in [0.0, 0.5, 1.0])
              Padding(
                padding: const EdgeInsets.all(8),
                child: Text(
                  't = $t   highlighted text',
                  style: TextStyle.lerp(redStyle, null, t),
                ),
              ),
          ],
        ),
      ),
    ),
  ));
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.47.9, on Microsoft Windows [Version 10.0.26200.9711], locale en-US) [292ms]
    • Flutter version 3.47.9 on channel stable at E:\projects\flutter\sdk-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c197ca5199 (8 days ago), 2026-10-29 10:10:20 -0400
    • Engine revision 89c39edfdf
    • Dart version 3.13.7
    • DevTools version 2.60.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, no-enable-windows-desktop, no-enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[√] Windows Version (Windows 11 or higher, 25H2, 2009) [749ms]

[√] Chrome - develop for the web [8ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Connected device (2 available) [124ms]
    • Chrome (web) • chrome • web-javascript • Google Chrome 156.0.8078.81
    • Edge (web)   • edge   • web-javascript • Microsoft Edge 156.0.4314.58

[√] Network resources [253ms]
    • All expected network resources are available.

• No issues found!```

</details>

Activity

  1. added
    framework
    a: typography
    has reproducible steps
    team-framework
    found in release: 3.47
    on Nov 9, 2026
  2. mbcorona commented on Nov 9, 2026

    @mbcorona
    Member

    Thanks for the report and the fix @hangy233.

    Confirmed from source: in the b == null branch of TextStyle.lerp, backgroundColor lerps from null toward a.backgroundColor while color and decorationColor lerp the other way. PR #196153 is up with the one-line fix and a regression test.

    Routing to the framework team to review the PR.

  3. added
    triaged-framework
    P2
    on Nov 10, 2026
  4. justinmc commented on Nov 10, 2026

    @justinmc
    Contributor

    Sounds like a bug we should fix, thanks for the report.

  5. added a commit that references this issue on Nov 17, 2026
    e83635a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: typographyfound in release: 3.47frameworkhas reproducible stepsteam-frameworktriaged-framework

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions