Skip to content

ColorPickerInput shows alpha in the last chars of the HEX color #131

@rubinbasha

Description

@rubinbasha

I have a HueRingPicker in which I have enabled alpha. When the hex color is displayed the alpha channel value is shown as the last characters of the TextField, when instead alpha value should be always the first when enabled.

the current code that does it

  textEditingController.text = '#' +
      widget.color.red.toRadixString(16).toUpperCase().padLeft(2, '0') +
      widget.color.green.toRadixString(16).toUpperCase().padLeft(2, '0') +
      widget.color.blue.toRadixString(16).toUpperCase().padLeft(2, '0') +
      (widget.enableAlpha ? widget.color.alpha.toRadixString(16).toUpperCase().padLeft(2, '0') : '');

The solution is easy, just move the line up

if (inputColor != widget.color.value) {
  // ignore: prefer_interpolation_to_compose_strings
  textEditingController.text = '#' +
      (widget.enableAlpha ? widget.color.alpha.toRadixString(16).toUpperCase().padLeft(2, '0') : '') +
      widget.color.red.toRadixString(16).toUpperCase().padLeft(2, '0') +
      widget.color.green.toRadixString(16).toUpperCase().padLeft(2, '0') +
      widget.color.blue.toRadixString(16).toUpperCase().padLeft(2, '0') ;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions