Skip to content

Commit b762b3f

Browse files
authored
[cupertino_ui] Include selectionHandleColor in NoDefaultCupertinoThemeData equality (#13450)
`NoDefaultCupertinoThemeData.operator ==` and `hashCode` leave out `selectionHandleColor`, so two themes that differ only in that color compare equal. `CupertinoThemeData`, which extends it, already includes the field. Because `ThemeData ==` compares `cupertinoOverrideTheme`, an app that passes a `NoDefaultCupertinoThemeData` there and changes only its `selectionHandleColor` gets an "equal" `ThemeData`, and dependents aren't rebuilt. This adds the field to both methods, matching `CupertinoThemeData`, and adds a unit test. Fixes flutter/flutter#195391 ## Pre-Review Checklist
1 parent 99943dd commit b762b3f

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎packages/cupertino_ui/lib/src/theme.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ class NoDefaultCupertinoThemeData {
593593
other.textTheme == textTheme &&
594594
other.barBackgroundColor == barBackgroundColor &&
595595
other.scaffoldBackgroundColor == scaffoldBackgroundColor &&
596+
other.selectionHandleColor == selectionHandleColor &&
596597
other.applyThemeToAll == applyThemeToAll;
597598
}
598599

@@ -604,6 +605,7 @@ class NoDefaultCupertinoThemeData {
604605
textTheme,
605606
barBackgroundColor,
606607
scaffoldBackgroundColor,
608+
selectionHandleColor,
607609
applyThemeToAll,
608610
);
609611
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes `NoDefaultCupertinoThemeData` equality and `hashCode` ignoring `selectionHandleColor`.
3+
version: patch

‎packages/cupertino_ui/test/theme_test.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ void main() {
228228
final NoDefaultCupertinoThemeData c = a.copyWith(brightness: Brightness.light);
229229
expect(a, equals(b));
230230
expect(a, isNot(c));
231+
232+
const red = NoDefaultCupertinoThemeData(selectionHandleColor: CupertinoColors.systemRed);
233+
const blue = NoDefaultCupertinoThemeData(selectionHandleColor: CupertinoColors.systemBlue);
234+
final NoDefaultCupertinoThemeData redCopy = red.copyWith();
235+
expect(red, isNot(blue));
236+
expect(red, equals(redCopy));
237+
expect(red.hashCode, redCopy.hashCode);
238+
expect(red.hashCode, isNot(blue.hashCode));
231239
});
232240

233241
late Brightness currentBrightness;

0 commit comments

Comments
 (0)