Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android colors are inconsistent with regards to alpha and hard to use. #562

Closed
felix-ht opened this issue Mar 3, 2021 · 1 comment
Closed
Labels

Comments

@felix-ht
Copy link
Collaborator

felix-ht commented Mar 3, 2021

Summary

Colors with alpha in android show inconsistent behavior between update and create.

For creation colors follow must follow rgba(r, g, b, a) or #rgb while #argb is not supported.

If a fill gets updated, the color must follow them pattern #argb or #rgb while rgba(r, g, b, a) is not supported.

Analysis

The reason for this is that for fill#add the FillBuilder is used while for fill#update FillController is used.
Only the Fill Controller calls Color.praseColor:
fill.setFillColor(Color.parseColor(fillColor));
while the FillBuilder directly uses the passed color string.
fillOptions.withFillColor(fillColor);

Proposal

The Proposal how to address this is two fold: Firstly have both FillBuilder FillController use Color.parseColor. Existing implementations that don't rely on alpha will not be broken.

Secondly change FillOptions, CircleOptions, and LineOptions to use Flutter Colors. Deprecate the old string colors.

Dealing with Strings in Flutter is pretty weird, especially because color toString does not provide an a string that can be used.

The suggest interface for FillOptions would look like so:

...
  final Color color;
  final Color outlineColor;
...
  const FillOptions(
      {this.fillOpacity,
      @deprecated this.fillColor,
      this.color,
      @deprecated this.fillOutlineColor,
      this.outlineColor,
      this.fillPattern,
      this.geometry,
      this.draggable});

The other geometry types should be changed similarly as well. Opacity could be deprecated as well as this can easily be controlled with the standard color tools everybody is used to such as color.withAlpha(value).

@stale
Copy link

stale bot commented Jan 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 14, 2022
@stale stale bot closed this as completed Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant