-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
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.