Skip to content

Color.lerp does not maintain equality #155803

@nate-thegrate

Description

@nate-thegrate

Use case

I'd like to make sure a widget only rebuilds when colorScheme.primary changes.


Test

import 'dart:ui';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('Color can lerp and maintain equality with itself', () {
    const color = Color(0xFF123456);

    expect(Color.lerp(color, color, 0.0), color);
    expect(Color.lerp(color, color, 0.1), color);
    expect(Color.lerp(color, color, 0.2), color);
    expect(Color.lerp(color, color, 0.3), color);
    expect(Color.lerp(color, color, 0.4), color);
    expect(Color.lerp(color, color, 0.5), color);
    expect(Color.lerp(color, color, 0.6), color);
    expect(Color.lerp(color, color, 0.7), color);
    expect(Color.lerp(color, color, 0.8), color);
    expect(Color.lerp(color, color, 0.9), color);
  });
}

The test fails due to tiny floating point rounding errors 😃 😃

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: annoyanceRepeatedly frustrating issues with non-experimental functionalityc: performanceRelates to speed or footprint issues (see "perf:" labels)fyi-designFor the attention of Design Languages teamteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions