Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 97d273c

Browse files
authored
CupertinoThemeData equality (#119480)
1 parent e1f0b1d commit 97d273c

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

packages/flutter/lib/src/cupertino/text_theme.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,41 @@ class CupertinoTextThemeData with Diagnosticable {
260260
properties.add(DiagnosticsProperty<TextStyle>('pickerTextStyle', pickerTextStyle, defaultValue: defaultData.pickerTextStyle));
261261
properties.add(DiagnosticsProperty<TextStyle>('dateTimePickerTextStyle', dateTimePickerTextStyle, defaultValue: defaultData.dateTimePickerTextStyle));
262262
}
263+
264+
@override
265+
bool operator == (Object other) {
266+
if (identical(this, other)) {
267+
return true;
268+
}
269+
if (other.runtimeType != runtimeType) {
270+
return false;
271+
}
272+
return other is CupertinoTextThemeData
273+
&& other._defaults == _defaults
274+
&& other._primaryColor == _primaryColor
275+
&& other._textStyle == _textStyle
276+
&& other._actionTextStyle == _actionTextStyle
277+
&& other._tabLabelTextStyle == _tabLabelTextStyle
278+
&& other._navTitleTextStyle == _navTitleTextStyle
279+
&& other._navLargeTitleTextStyle == _navLargeTitleTextStyle
280+
&& other._navActionTextStyle == _navActionTextStyle
281+
&& other._pickerTextStyle == _pickerTextStyle
282+
&& other._dateTimePickerTextStyle == _dateTimePickerTextStyle;
283+
}
284+
285+
@override
286+
int get hashCode => Object.hash(
287+
_defaults,
288+
_primaryColor,
289+
_textStyle,
290+
_actionTextStyle,
291+
_tabLabelTextStyle,
292+
_navTitleTextStyle,
293+
_navLargeTitleTextStyle,
294+
_navActionTextStyle,
295+
_pickerTextStyle,
296+
_dateTimePickerTextStyle,
297+
);
263298
}
264299

265300

@@ -296,4 +331,20 @@ class _TextThemeDefaultsBuilder {
296331
? this
297332
: _TextThemeDefaultsBuilder(resolvedLabelColor, resolvedInactiveGray);
298333
}
334+
335+
@override
336+
bool operator == (Object other) {
337+
if (identical(this, other)) {
338+
return true;
339+
}
340+
if (other.runtimeType != runtimeType) {
341+
return false;
342+
}
343+
return other is _TextThemeDefaultsBuilder
344+
&& other.labelColor == labelColor
345+
&& other.inactiveGrayColor == inactiveGrayColor;
346+
}
347+
348+
@override
349+
int get hashCode => Object.hash(labelColor, inactiveGrayColor);
299350
}

packages/flutter/lib/src/cupertino/theme.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,35 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
311311
properties.add(DiagnosticsProperty<bool>('applyThemeToAll', applyThemeToAll, defaultValue: defaultData.applyThemeToAll));
312312
textTheme.debugFillProperties(properties);
313313
}
314+
315+
@override
316+
bool operator == (Object other) {
317+
if (identical(this, other)) {
318+
return true;
319+
}
320+
if (other.runtimeType != runtimeType) {
321+
return false;
322+
}
323+
return other is CupertinoThemeData
324+
&& other.brightness == brightness
325+
&& other.primaryColor == primaryColor
326+
&& other.primaryContrastingColor == primaryContrastingColor
327+
&& other.textTheme == textTheme
328+
&& other.barBackgroundColor == barBackgroundColor
329+
&& other.scaffoldBackgroundColor == scaffoldBackgroundColor
330+
&& other.applyThemeToAll == applyThemeToAll;
331+
}
332+
333+
@override
334+
int get hashCode => Object.hash(
335+
brightness,
336+
primaryColor,
337+
primaryContrastingColor,
338+
textTheme,
339+
barBackgroundColor,
340+
scaffoldBackgroundColor,
341+
applyThemeToAll,
342+
);
314343
}
315344

316345
/// Styling specifications for a cupertino theme without default values for

packages/flutter/test/cupertino/theme_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ void main() {
212212
);
213213
});
214214

215+
testWidgets('CupertinoThemeData equality', (WidgetTester tester) async {
216+
const CupertinoThemeData a = CupertinoThemeData(brightness: Brightness.dark);
217+
final CupertinoThemeData b = a.copyWith();
218+
final CupertinoThemeData c = a.copyWith(brightness: Brightness.light);
219+
expect(a, equals(b));
220+
expect(b, equals(a));
221+
expect(a, isNot(equals(c)));
222+
expect(c, isNot(equals(a)));
223+
expect(b, isNot(equals(c)));
224+
expect(c, isNot(equals(b)));
225+
});
226+
215227
late Brightness currentBrightness;
216228
void colorMatches(Color? componentColor, CupertinoDynamicColor expectedDynamicColor) {
217229
switch (currentBrightness) {

packages/flutter/test/material/theme_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,12 @@ void main() {
644644
primarySwatch: Colors.blue,
645645
cupertinoOverrideTheme: const CupertinoThemeData(
646646
// But the primary material color is preempted by the override.
647-
primaryColor: CupertinoColors.activeOrange,
647+
primaryColor: CupertinoColors.systemRed,
648648
),
649649
));
650650

651651
expect(buildCount, 2);
652-
expect(theme.primaryColor, CupertinoColors.activeOrange);
652+
expect(theme.primaryColor, CupertinoColors.systemRed);
653653
},
654654
);
655655

0 commit comments

Comments
 (0)