@@ -22,6 +22,7 @@ const _CupertinoThemeDefaults _kDefaultTheme = _CupertinoThemeDefaults(
22
22
// Values extracted from navigation bar. For toolbar or tabbar the dark color is 0xF0161616.
23
23
),
24
24
CupertinoColors .systemBackground,
25
+ false ,
25
26
_CupertinoTextThemeDefaults (CupertinoColors .label, CupertinoColors .inactiveGray),
26
27
);
27
28
@@ -172,13 +173,15 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
172
173
CupertinoTextThemeData ? textTheme,
173
174
Color ? barBackgroundColor,
174
175
Color ? scaffoldBackgroundColor,
176
+ bool ? applyThemeToAll,
175
177
}) : this .raw (
176
178
brightness,
177
179
primaryColor,
178
180
primaryContrastingColor,
179
181
textTheme,
180
182
barBackgroundColor,
181
183
scaffoldBackgroundColor,
184
+ applyThemeToAll,
182
185
);
183
186
184
187
/// Same as the default constructor but with positional arguments to avoid
@@ -193,13 +196,15 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
193
196
CupertinoTextThemeData ? textTheme,
194
197
Color ? barBackgroundColor,
195
198
Color ? scaffoldBackgroundColor,
199
+ bool ? applyThemeToAll,
196
200
) : this ._rawWithDefaults (
197
201
brightness,
198
202
primaryColor,
199
203
primaryContrastingColor,
200
204
textTheme,
201
205
barBackgroundColor,
202
206
scaffoldBackgroundColor,
207
+ applyThemeToAll,
203
208
_kDefaultTheme,
204
209
);
205
210
@@ -210,6 +215,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
210
215
CupertinoTextThemeData ? textTheme,
211
216
Color ? barBackgroundColor,
212
217
Color ? scaffoldBackgroundColor,
218
+ bool ? applyThemeToAll,
213
219
this ._defaults,
214
220
) : super (
215
221
brightness: brightness,
@@ -218,6 +224,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
218
224
textTheme: textTheme,
219
225
barBackgroundColor: barBackgroundColor,
220
226
scaffoldBackgroundColor: scaffoldBackgroundColor,
227
+ applyThemeToAll: applyThemeToAll,
221
228
);
222
229
223
230
final _CupertinoThemeDefaults _defaults;
@@ -239,6 +246,9 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
239
246
@override
240
247
Color get scaffoldBackgroundColor => super .scaffoldBackgroundColor ?? _defaults.scaffoldBackgroundColor;
241
248
249
+ @override
250
+ bool get applyThemeToAll => super .applyThemeToAll ?? _defaults.applyThemeToAll;
251
+
242
252
@override
243
253
NoDefaultCupertinoThemeData noDefault () {
244
254
return NoDefaultCupertinoThemeData (
@@ -248,6 +258,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
248
258
textTheme: super .textTheme,
249
259
barBackgroundColor: super .barBackgroundColor,
250
260
scaffoldBackgroundColor: super .scaffoldBackgroundColor,
261
+ applyThemeToAll: super .applyThemeToAll,
251
262
);
252
263
}
253
264
@@ -262,6 +273,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
262
273
super .textTheme? .resolveFrom (context),
263
274
convertColor (super .barBackgroundColor),
264
275
convertColor (super .scaffoldBackgroundColor),
276
+ applyThemeToAll,
265
277
_defaults.resolveFrom (context, super .textTheme == null ),
266
278
);
267
279
}
@@ -274,6 +286,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
274
286
CupertinoTextThemeData ? textTheme,
275
287
Color ? barBackgroundColor,
276
288
Color ? scaffoldBackgroundColor,
289
+ bool ? applyThemeToAll,
277
290
}) {
278
291
return CupertinoThemeData ._rawWithDefaults (
279
292
brightness ?? super .brightness,
@@ -282,6 +295,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
282
295
textTheme ?? super .textTheme,
283
296
barBackgroundColor ?? super .barBackgroundColor,
284
297
scaffoldBackgroundColor ?? super .scaffoldBackgroundColor,
298
+ applyThemeToAll ?? super .applyThemeToAll,
285
299
_defaults,
286
300
);
287
301
}
@@ -295,6 +309,7 @@ class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable
295
309
properties.add (createCupertinoColorProperty ('primaryContrastingColor' , primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor));
296
310
properties.add (createCupertinoColorProperty ('barBackgroundColor' , barBackgroundColor, defaultValue: defaultData.barBackgroundColor));
297
311
properties.add (createCupertinoColorProperty ('scaffoldBackgroundColor' , scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor));
312
+ properties.add (DiagnosticsProperty <bool >('applyThemeToAll' , applyThemeToAll, defaultValue: defaultData.applyThemeToAll));
298
313
textTheme.debugFillProperties (properties);
299
314
}
300
315
}
@@ -322,6 +337,7 @@ class NoDefaultCupertinoThemeData {
322
337
this .textTheme,
323
338
this .barBackgroundColor,
324
339
this .scaffoldBackgroundColor,
340
+ this .applyThemeToAll,
325
341
});
326
342
327
343
/// The brightness override for Cupertino descendants.
@@ -389,6 +405,22 @@ class NoDefaultCupertinoThemeData {
389
405
/// Defaults to [CupertinoColors.systemBackground] .
390
406
final Color ? scaffoldBackgroundColor;
391
407
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
+
392
424
/// Returns an instance of the theme data whose property getters only return
393
425
/// the construction time specifications with no derived values.
394
426
///
@@ -412,6 +444,7 @@ class NoDefaultCupertinoThemeData {
412
444
textTheme: textTheme? .resolveFrom (context),
413
445
barBackgroundColor: convertColor (barBackgroundColor),
414
446
scaffoldBackgroundColor: convertColor (scaffoldBackgroundColor),
447
+ applyThemeToAll: applyThemeToAll,
415
448
);
416
449
}
417
450
@@ -428,6 +461,7 @@ class NoDefaultCupertinoThemeData {
428
461
CupertinoTextThemeData ? textTheme,
429
462
Color ? barBackgroundColor ,
430
463
Color ? scaffoldBackgroundColor,
464
+ bool ? applyThemeToAll,
431
465
}) {
432
466
return NoDefaultCupertinoThemeData (
433
467
brightness: brightness ?? this .brightness,
@@ -436,6 +470,7 @@ class NoDefaultCupertinoThemeData {
436
470
textTheme: textTheme ?? this .textTheme,
437
471
barBackgroundColor: barBackgroundColor ?? this .barBackgroundColor,
438
472
scaffoldBackgroundColor: scaffoldBackgroundColor ?? this .scaffoldBackgroundColor,
473
+ applyThemeToAll: applyThemeToAll ?? this .applyThemeToAll,
439
474
);
440
475
}
441
476
}
@@ -448,6 +483,7 @@ class _CupertinoThemeDefaults {
448
483
this .primaryContrastingColor,
449
484
this .barBackgroundColor,
450
485
this .scaffoldBackgroundColor,
486
+ this .applyThemeToAll,
451
487
this .textThemeDefaults,
452
488
);
453
489
@@ -456,6 +492,7 @@ class _CupertinoThemeDefaults {
456
492
final Color primaryContrastingColor;
457
493
final Color barBackgroundColor;
458
494
final Color scaffoldBackgroundColor;
495
+ final bool applyThemeToAll;
459
496
final _CupertinoTextThemeDefaults textThemeDefaults;
460
497
461
498
_CupertinoThemeDefaults resolveFrom (BuildContext context, bool resolveTextTheme) {
@@ -467,6 +504,7 @@ class _CupertinoThemeDefaults {
467
504
convertColor (primaryContrastingColor),
468
505
convertColor (barBackgroundColor),
469
506
convertColor (scaffoldBackgroundColor),
507
+ applyThemeToAll,
470
508
resolveTextTheme ? textThemeDefaults.resolveFrom (context) : textThemeDefaults,
471
509
);
472
510
}
0 commit comments