Skip to content

HSVColor.lerp and HSLColor.lerp don't interpolate hue via 0 #138301

Closed

Description

@zeezooz

Is there an existing issue for this?

Steps to reproduce

Use HSVColor.lerp or HSLColor.lerp to interpolate between a color with a hue close to 360 (for example, HSVColor.fromAHSV(1, 300, 1, 1)) and a color with a hue close to 0 (for example, HSVColor.fromAHSV(1, 60, 1, 1)) so that the difference is greater than 180.

Expected results

The resulting hue is interpolated using the shortest path: 300 -> 360(0) -> 60.

Actual results

The resulting hue is interpolated using the longest path: 300 -> 180 -> 60.

Code sample

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: SizedBox(
            width: 100,
            height: 100,
            child: ColorAnimation(),
          ),
        ),
      ),
    );
  }
}

class ColorAnimation extends StatefulWidget {
  const ColorAnimation({Key? key}) : super(key: key);

  @override
  State<ColorAnimation> createState() => _ColorAnimationState();
}

class _ColorAnimationState extends State<ColorAnimation>
    with SingleTickerProviderStateMixin {
  late final controller = AnimationController(
    duration: const Duration(seconds: 24),
    vsync: this,
  );
  late final animation = HSVColorTween(
    begin: const HSVColor.fromAHSV(1, 300, 1, 1),
    end: const HSVColor.fromAHSV(1, 60, 1, 1),
  ).animate(controller);

  @override
  void initState() {
    super.initState();
    controller.repeat(reverse: true);
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ListenableBuilder(
      listenable: animation,
      builder: (context, child) {
        return ColoredBox(
          color: animation.value!.toColor(),
          child: Center(
            child: Text(animation.value!.hue.round().toString()),
          ),
        );
      },
    );
  }
}

class HSVColorTween extends Tween<HSVColor?> {
  HSVColorTween({super.begin, super.end});

  @override
  HSVColor? lerp(double t) => HSVColor.lerp(begin, end, t);
}

Screenshots or Video

Screenshots / Video demonstration

image

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.9, on macOS 14.1 23B74 darwin-arm64, locale en-UA)
    • Flutter version 3.13.9 on channel stable at /Users/andrew/Applications/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (2 weeks ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/andrew/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/andrew/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10811636/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/andrew/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10811636/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/andrew/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.11005911/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.1 23B74 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 119.0.6045.123

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Nov 13, 2023
  2. huycozy commented on Nov 13, 2023

    @huycozy
    Member

    Reproduced the issue on master channel as well.

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.13.9, on macOS 14.1 23B74 darwin-x64, locale en-VN)
        • Flutter version 3.13.9 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d211f42860 (11 days ago), 2023-10-25 13:42:25 -0700
        • Engine revision 0545f8705d
        • Dart version 3.1.5
        • DevTools version 2.25.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
        • Xcode at /Users/huynq/Downloads/Xcode.app/Contents/Developer
        • Build 15A507
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Applications/Android Studio Giraffe.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • android-studio-dir = /Applications/Android Studio.app/
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.84.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.76.0
    
    [✓] Connected device (4 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D                         • android-arm64  • Android 11 (API 30)
        • iPhone (mobile)  • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios            • iOS 15.7.9 19H365
        • macOS (desktop)  • macos                                    • darwin-x64     • macOS 14.1 23B74 darwin-x64
        • Chrome (web)     • chrome                                   • web-javascript • Google Chrome 118.0.5993.117
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.17.0-5.0.pre.64, on macOS 14.1 23B74 darwin-x64, locale en-VN)
        • Flutter version 3.17.0-5.0.pre.64 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2e088178e8 (4 hours ago), 2023-11-12 18:45:26 -0500
        • Engine revision a18ee3c7f5
        • Dart version 3.3.0 (build 3.3.0-120.0.dev)
        • DevTools version 2.30.0-dev.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15A507
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Applications/Android Studio Giraffe.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Applications/Android Studio Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build 17.0.8+0-17.0.8b1000.22-10799086)
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • android-studio-dir = /Applications/Android Studio.app/
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.76.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 14.1 23B74 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 119.0.6045.123
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Nov 13, 2023
  4. added
    P2Important issues not at the top of the work list
    on Nov 14, 2023
  5. added a commit that references this issue on Aug 26, 2026
    9c6540e
  6. github-actions commented on Sep 9, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Sep 9, 2026
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

    P2Important issues not at the top of the work listfound in release: 3.13Found to occur in 3.13found in release: 3.17Found to occur in 3.17frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-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