Skip to content

HSLColor.fromColor treats black as fully saturated #166460

@mateusfccp

Description

@mateusfccp

Steps to reproduce

  1. Create a HSLColor with HSLColor.fromColor(const Color(0xFF000000)).
  2. Check the saturation of the color with hslColor.saturation.

Expected results

Just like for white and any other shade of pure gray (you can test, for instance, with the almost black 0xFF010101), the saturation should be 0.0.

Actual results

The saturation is 1.0.

Code sample

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

void main() {
  final hslColor = HSLColor.fromColor(const Color(0xFF000000));
  print(hslColor.saturation);
}

Screenshots or Video

Because of this, when you want to create a sequence of colors from the black to the light, it becomes red.

Image

Instead, it should step from black to light through gray (example using 0xFF010101).

Image

Logs

Logs Not relevant.

Flutter Doctor output

Doctor output
[redacted] git:(master) ✗ flutter doctor -v
[✓] Flutter (Channel stable, 3.29.2, on macOS 15.3.2 24D81 darwin-arm64, locale
    en-AR) [393ms]
    • Flutter version 3.29.2 on channel stable at
      /Users/[redacted]/.puro/envs/stable/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c236373904 (3 weeks ago), 2025-03-13 16:17:06 -0400
    • Engine revision 18b71d647a
    • Dart version 3.7.2
    • DevTools version 2.42.3

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    [489ms]
    • Android SDK at /Users/[redacted]/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2) [2.5s]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.2) [15ms]
    • 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
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)

[✓] Connected device (3 available) [6.6s]
    • macOS (desktop)                 • macos                 • darwin-arm64   •
      macOS 15.3.2 24D81 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         •
      macOS 15.3.2 24D81 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript •
      Google Chrome 134.0.6998.166

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

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31frameworkflutter/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