@@ -22,6 +22,7 @@ const _CupertinoThemeDefaults _kDefaultTheme = _CupertinoThemeDefaults(
2222 // Values extracted from navigation bar. For toolbar or tabbar the dark color is 0xF0161616.
2323 ),
2424 CupertinoColors .systemBackground,
25+ false ,
2526 _CupertinoTextThemeDefaults (CupertinoColors .label, CupertinoColors .inactiveGray),
2627);
2728
@@ -172,13 +173,15 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
172173 CupertinoTextThemeData ? textTheme,
173174 Color ? barBackgroundColor,
174175 Color ? scaffoldBackgroundColor,
176+ bool ? applyThemeToAll,
175177 }) : this .raw (
176178 brightness,
177179 primaryColor,
178180 primaryContrastingColor,
179181 textTheme,
180182 barBackgroundColor,
181183 scaffoldBackgroundColor,
184+ applyThemeToAll,
182185 );
183186
184187 /// Same as the default constructor but with positional arguments to avoid
@@ -193,13 +196,15 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
193196 CupertinoTextThemeData ? textTheme,
194197 Color ? barBackgroundColor,
195198 Color ? scaffoldBackgroundColor,
199+ bool ? applyThemeToAll,
196200 ) : this ._rawWithDefaults (
197201 brightness,
198202 primaryColor,
199203 primaryContrastingColor,
200204 textTheme,
201205 barBackgroundColor,
202206 scaffoldBackgroundColor,
207+ applyThemeToAll,
203208 _kDefaultTheme,
204209 );
205210
@@ -210,6 +215,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
210215 CupertinoTextThemeData ? textTheme,
211216 Color ? barBackgroundColor,
212217 Color ? scaffoldBackgroundColor,
218+ bool ? applyThemeToAll,
213219 this ._defaults,
214220 ) : super (
215221 brightness: brightness,
@@ -218,6 +224,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
218224 textTheme: textTheme,
219225 barBackgroundColor: barBackgroundColor,
220226 scaffoldBackgroundColor: scaffoldBackgroundColor,
227+ applyThemeToAll: applyThemeToAll,
221228 );
222229
223230 final _CupertinoThemeDefaults _defaults;
@@ -239,6 +246,9 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
239246 @override
240247 Color get scaffoldBackgroundColor => super .scaffoldBackgroundColor ?? _defaults.scaffoldBackgroundColor;
241248
249+ @override
250+ bool get applyThemeToAll => super .applyThemeToAll ?? _defaults.applyThemeToAll;
251+
242252 @override
243253 NoDefaultCupertinoThemeData noDefault () {
244254 return NoDefaultCupertinoThemeData (
@@ -248,6 +258,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
248258 textTheme: super .textTheme,
249259 barBackgroundColor: super .barBackgroundColor,
250260 scaffoldBackgroundColor: super .scaffoldBackgroundColor,
261+ applyThemeToAll: super .applyThemeToAll,
251262 );
252263 }
253264
@@ -262,6 +273,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
262273 super .textTheme? .resolveFrom (context),
263274 convertColor (super .barBackgroundColor),
264275 convertColor (super .scaffoldBackgroundColor),
276+ applyThemeToAll,
265277 _defaults.resolveFrom (context, super .textTheme == null ),
266278 );
267279 }
@@ -274,6 +286,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
274286 CupertinoTextThemeData ? textTheme,
275287 Color ? barBackgroundColor,
276288 Color ? scaffoldBackgroundColor,
289+ bool ? applyThemeToAll,
277290 }) {
278291 return CupertinoThemeData ._rawWithDefaults (
279292 brightness ?? super .brightness,
@@ -282,6 +295,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
282295 textTheme ?? super .textTheme,
283296 barBackgroundColor ?? super .barBackgroundColor,
284297 scaffoldBackgroundColor ?? super .scaffoldBackgroundColor,
298+ applyThemeToAll ?? super .applyThemeToAll,
285299 _defaults,
286300 );
287301 }
@@ -295,6 +309,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
295309 properties.add (createCupertinoColorProperty ('primaryContrastingColor' , primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor));
296310 properties.add (createCupertinoColorProperty ('barBackgroundColor' , barBackgroundColor, defaultValue: defaultData.barBackgroundColor));
297311 properties.add (createCupertinoColorProperty ('scaffoldBackgroundColor' , scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor));
312+ properties.add (DiagnosticsProperty <bool >('applyThemeToAll' , applyThemeToAll, defaultValue: defaultData.applyThemeToAll));
298313 textTheme.debugFillProperties (properties);
299314 }
300315}
@@ -322,6 +337,7 @@ class NoDefaultCupertinoThemeData {
322337 this .textTheme,
323338 this .barBackgroundColor,
324339 this .scaffoldBackgroundColor,
340+ this .applyThemeToAll,
325341 });
326342
327343 /// The brightness override for Cupertino descendants.
@@ -389,6 +405,22 @@ class NoDefaultCupertinoThemeData {
389405 /// Defaults to [CupertinoColors.systemBackground] .
390406 final Color ? scaffoldBackgroundColor;
391407
408+ /// Flag to apply this theme to all descendant Cupertino widgets.
409+ ///
410+ /// Certain Cupertino widgets previously didn't use theming, matching past
411+ /// versions of iOS. For example, [CupertinoSwitch] s always used
412+ /// [CupertinoColors.systemGreen] when active.
413+ ///
414+ /// Today, however, these widgets can indeed be themed on iOS. Moreover on
415+ /// macOS, the accent color is reflected in these widgets. Turning this flag
416+ /// on ensures that descendant Cupertino widgets will be themed accordingly.
417+ ///
418+ /// This flag currently applies to the following widgets:
419+ /// - [CupertinoSwitch] & [Switch.adaptive]
420+ ///
421+ /// Defaults to false.
422+ final bool ? applyThemeToAll;
423+
392424 /// Returns an instance of the theme data whose property getters only return
393425 /// the construction time specifications with no derived values.
394426 ///
@@ -412,6 +444,7 @@ class NoDefaultCupertinoThemeData {
412444 textTheme: textTheme? .resolveFrom (context),
413445 barBackgroundColor: convertColor (barBackgroundColor),
414446 scaffoldBackgroundColor: convertColor (scaffoldBackgroundColor),
447+ applyThemeToAll: applyThemeToAll,
415448 );
416449 }
417450
@@ -428,6 +461,7 @@ class NoDefaultCupertinoThemeData {
428461 CupertinoTextThemeData ? textTheme,
429462 Color ? barBackgroundColor ,
430463 Color ? scaffoldBackgroundColor,
464+ bool ? applyThemeToAll,
431465 }) {
432466 return NoDefaultCupertinoThemeData (
433467 brightness: brightness ?? this .brightness,
@@ -436,6 +470,7 @@ class NoDefaultCupertinoThemeData {
436470 textTheme: textTheme ?? this .textTheme,
437471 barBackgroundColor: barBackgroundColor ?? this .barBackgroundColor,
438472 scaffoldBackgroundColor: scaffoldBackgroundColor ?? this .scaffoldBackgroundColor,
473+ applyThemeToAll: applyThemeToAll ?? this .applyThemeToAll,
439474 );
440475 }
441476}
@@ -448,6 +483,7 @@ class _CupertinoThemeDefaults {
448483 this .primaryContrastingColor,
449484 this .barBackgroundColor,
450485 this .scaffoldBackgroundColor,
486+ this .applyThemeToAll,
451487 this .textThemeDefaults,
452488 );
453489
@@ -456,6 +492,7 @@ class _CupertinoThemeDefaults {
456492 final Color primaryContrastingColor;
457493 final Color barBackgroundColor;
458494 final Color scaffoldBackgroundColor;
495+ final bool applyThemeToAll;
459496 final _CupertinoTextThemeDefaults textThemeDefaults;
460497
461498 _CupertinoThemeDefaults resolveFrom (BuildContext context, bool resolveTextTheme) {
@@ -467,6 +504,7 @@ class _CupertinoThemeDefaults {
467504 convertColor (primaryContrastingColor),
468505 convertColor (barBackgroundColor),
469506 convertColor (scaffoldBackgroundColor),
507+ applyThemeToAll,
470508 resolveTextTheme ? textThemeDefaults.resolveFrom (context) : textThemeDefaults,
471509 );
472510 }
0 commit comments