Summary

#

Certain properties and methods in CupertinoDynamicColor were deprecated to align with the Color class due to wide gamut color spaces support added in Flutter 3.27.

Context

#

The Color class was updated to support wide gamut color spaces, but some corresponding deprecations were not initially applied to CupertinoDynamicColor due to its implementation rather than due to the extension of Color.

Description of change

#
  1. The CupertinoDynamicColor.red is deprecated in favor of CupertinoDynamicColor.r.
  2. The CupertinoDynamicColor.green is deprecated in favor of CupertinoDynamicColor.g.
  3. The CupertinoDynamicColor.blue is deprecated in favor of CupertinoDynamicColor.b.
  4. The CupertinoDynamicColor.opacity is deprecated in favor of CupertinoDynamicColor.a.
  5. The CupertinoDynamicColor.withOpacity() is deprecated in favor of CupertinoDynamicColor.withValues().

Migration guide

#

Access color components

#

If your app accesses a single color component, consider taking advantage of the floating-point components. In the short term, you can scale the components themselves.

dart
int _floatToInt8(double x) {
  return (x * 255.0).round().clamp(0, 255);
}

const CupertinoDynamicColor color = CupertinoColors.systemBlue;
final intRed = _floatToInt8(color.r);
final intGreen = _floatToInt8(color.g);
final intBlue = _floatToInt8(color.b);

Opacity

#

Before Flutter 3.27, Color had the concept of "opacity", which showed up in the methods opacity and withOpacity(). Since Flutter 3.27, alpha is stored as a floating-point value. Using .a and .withValues() will give the full expression of a floating-point value and won't be quantized (restricted to a limited range). That means "alpha" expresses the intent of "opacity" more correctly.

Migrate opacity

#
dart
// Before: Access the alpha channel as a (converted) floating-point value.
final x = color.opacity;

// After: Access the alpha channel directly.
final x = color.a;

Migrate withOpacity

#
dart
// Before: Create a new color with the specified opacity.
final x = color.withOpacity(0.5);

// After: Create a new color with the specified alpha channel value,
// accounting for the current or specified color space.
final x = color.withValues(alpha: 0.5);

Timeline

#

Landed in version: 3.33.0-1.0.pre
Stable release: Not yet

References

#

Relevant guides:

Relevant issues:

Relevant PRs: