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).
This commit is contained in:
gaaclarke
2024-09-03 13:00:04 -07:00
committed by GitHub
parent 76955826ae
commit 52bb0c4cee

View File

@@ -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<Element>('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].