Migration guide for wide gamut CupertinoDynamicColor
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
#- The
CupertinoDynamicColor.red
is deprecated in favor ofCupertinoDynamicColor.r
. - The
CupertinoDynamicColor.green
is deprecated in favor ofCupertinoDynamicColor.g
. - The
CupertinoDynamicColor.blue
is deprecated in favor ofCupertinoDynamicColor.b
. - The
CupertinoDynamicColor.opacity
is deprecated in favor ofCupertinoDynamicColor.a
. - The
CupertinoDynamicColor.withOpacity()
is deprecated in favor ofCupertinoDynamicColor.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.
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
#// 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
#// 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:
- Implement wide gamut color support in the Framework
- CupertinoDynamicColor is missing deprecation notices
Relevant PRs:
Unless stated otherwise, the documentation on this site reflects the latest stable version of Flutter. Page last updated on 2025-07-23. View source or report an issue.