Skip to content

Color term for "alpha" and "opacity" is ambiguous, also deprecation seems odd #154491

@matthew-carroll

Description

@matthew-carroll

withOpacity was just deprecated in Color (in Engine lib/ui/painting.dart) in favor of a new method called withValues().

First, there's now a mismatch for the names "alpha" and "opacity". Up to this point, the term "alpha" within Color always refers to an integer value in the range [0, 255]. "Opacity" refers to a fraction in the range [0.0, 1.0]. But the withValues() signature is as follows:

Color withValues(
      {double? alpha,
      double? red,
      double? green,
      double? blue,
      ColorSpace? colorSpace}) {
  // ...
}

Thus, the term "alpha" has now been introduced in the form of what was previously called "opacity".

Second, withOpacity() has been deprecated:

@Deprecated('Use .withValues() to avoid precision loss.')

It's not clear to me why withOpacity() has been deprecated. If colorSpace can be null then there must be a default color space, which I assume produces the exact same result as before when calling withOpacity. So if withOpacity always worked before, why can't it continue to work now, as expected?

Moreover, the reason that withOpacity() exists in the first place was because the adjustment of opacity was so common as to warrant it's own method. If the goal is to support color spaces, then why not add an optional ColorSpace parameter to withOpacity(), which wouldn't be API breaking, and then apply that ColorSpace if provided? Otherwise, this change seems like a DevX downgrade - even if it does solve a technical problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.r: solvedIssue is closed as solvedteam-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions