diff --git a/packages/flutter/lib/src/cupertino/theme.dart b/packages/flutter/lib/src/cupertino/theme.dart index eff62423aa8..db0a330abc4 100644 --- a/packages/flutter/lib/src/cupertino/theme.dart +++ b/packages/flutter/lib/src/cupertino/theme.dart @@ -394,6 +394,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable /// /// * [CupertinoThemeData], which uses reasonable default values for /// unspecified theme properties. +@immutable class NoDefaultCupertinoThemeData { /// Creates a [NoDefaultCupertinoThemeData] styling specification. /// @@ -541,6 +542,35 @@ class NoDefaultCupertinoThemeData { applyThemeToAll: applyThemeToAll ?? this.applyThemeToAll, ); } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is NoDefaultCupertinoThemeData && + other.brightness == brightness && + other.primaryColor == primaryColor && + other.primaryContrastingColor == primaryContrastingColor && + other.textTheme == textTheme && + other.barBackgroundColor == barBackgroundColor && + other.scaffoldBackgroundColor == scaffoldBackgroundColor && + other.applyThemeToAll == applyThemeToAll; + } + + @override + int get hashCode => Object.hash( + brightness, + primaryColor, + primaryContrastingColor, + textTheme, + barBackgroundColor, + scaffoldBackgroundColor, + applyThemeToAll, + ); } @immutable diff --git a/packages/flutter/test/cupertino/theme_test.dart b/packages/flutter/test/cupertino/theme_test.dart index ae94dfff568..78e469276d5 100644 --- a/packages/flutter/test/cupertino/theme_test.dart +++ b/packages/flutter/test/cupertino/theme_test.dart @@ -221,6 +221,14 @@ void main() { expect(c, isNot(equals(b))); }); + testWidgets('NoDefaultCupertinoThemeData equality', (WidgetTester tester) async { + const NoDefaultCupertinoThemeData a = NoDefaultCupertinoThemeData(); + final NoDefaultCupertinoThemeData b = a.copyWith(); + final NoDefaultCupertinoThemeData c = a.copyWith(brightness: Brightness.light); + expect(a, equals(b)); + expect(a, isNot(c)); + }); + late Brightness currentBrightness; void colorMatches(Color? componentColor, Color expectedDynamicColor) { if (expectedDynamicColor is CupertinoDynamicColor) {