From 52bb0c4cee5568dfe1fd6fadcabc97f460757eb8 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:00:04 -0700 Subject: [PATCH] Switched CupertinoDynamicColor to `implements Color` (#153938) issue: https://github.com/flutter/flutter/issues/127855 This was an impediment to [changing the Color class](https://github.com/flutter/engine/pull/54415). --- .../flutter/lib/src/cupertino/colors.dart | 77 ++++++++++++++++--- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/colors.dart b/packages/flutter/lib/src/cupertino/colors.dart index ff2d66b066..5f1b4c2783 100644 --- a/packages/flutter/lib/src/cupertino/colors.dart +++ b/packages/flutter/lib/src/cupertino/colors.dart @@ -8,7 +8,7 @@ /// @docImport 'nav_bar.dart'; library; -import 'dart:ui' show Brightness, Color; +import 'dart:ui' show Brightness, Color, ColorSpace; import '../../foundation.dart'; import '../widgets/basic.dart'; @@ -748,7 +748,7 @@ abstract final class CupertinoColors { /// * [CupertinoTheme.of], a static method that retrieves the ambient [CupertinoThemeData], /// and then resolves [CupertinoDynamicColor]s used in the retrieved data. @immutable -class CupertinoDynamicColor extends Color with Diagnosticable { +class CupertinoDynamicColor with Diagnosticable implements Color { /// Creates an adaptive [Color] that changes its effective color based on the /// [BuildContext] given. The default effective color is [color]. const CupertinoDynamicColor({ @@ -828,10 +828,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable { this.darkHighContrastElevatedColor, this._debugResolveContext, this._debugLabel, - ) : // The super constructor has to be called with a dummy value in order to mark - // this constructor const. - // The field `value` is overridden in the class implementation. - super(0); + ); /// The current effective color. /// @@ -839,9 +836,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable { /// resolved. final Color _effectiveColor; - @override - int get value => _effectiveColor.value; - final String? _debugLabel; final Element? _debugResolveContext; @@ -1151,6 +1145,71 @@ class CupertinoDynamicColor extends Color with Diagnosticable { properties.add(DiagnosticsProperty('last resolved', _debugResolveContext)); } } + + @override + int get value => _effectiveColor.value; + + @override + int get alpha => _effectiveColor.alpha; + + @override + int get blue => _effectiveColor.blue; + + @override + double computeLuminance() => _effectiveColor.computeLuminance(); + + @override + int get green => _effectiveColor.green; + + @override + double get opacity => _effectiveColor.opacity; + + @override + int get red => _effectiveColor.red; + + @override + Color withAlpha(int a) => _effectiveColor.withAlpha(a); + + @override + Color withBlue(int b) => _effectiveColor.withBlue(b); + + @override + Color withGreen(int g) => _effectiveColor.withGreen(g); + + @override + Color withOpacity(double opacity) => _effectiveColor.withOpacity(opacity); + + @override + Color withRed(int r) => _effectiveColor.withRed(r); + + @override + double get a => _effectiveColor.a; + + @override + double get r => _effectiveColor.r; + + @override + double get g => _effectiveColor.g; + + @override + double get b => _effectiveColor.b; + + @override + ColorSpace get colorSpace => _effectiveColor.colorSpace; + + @override + Color withValues( + {double? alpha, + double? red, + double? green, + double? blue, + ColorSpace? colorSpace}) => + _effectiveColor.withValues( + alpha: alpha, + red: red, + green: green, + blue: blue, + colorSpace: colorSpace); } /// Creates a diagnostics property for [CupertinoDynamicColor].