theme.dart 21.5 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
xster's avatar
xster committed
2 3 4 5 6 7 8
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'colors.dart';
9
import 'icon_theme_data.dart';
xster's avatar
xster committed
10 11
import 'text_theme.dart';

12
export 'package:flutter/foundation.dart' show Brightness;
xster's avatar
xster committed
13 14

// Values derived from https://developer.apple.com/design/resources/.
15 16 17 18 19 20 21 22 23 24
const _CupertinoThemeDefaults _kDefaultTheme = _CupertinoThemeDefaults(
  null,
  CupertinoColors.systemBlue,
  CupertinoColors.systemBackground,
  CupertinoDynamicColor.withBrightness(
    color: Color(0xF0F9F9F9),
    darkColor: Color(0xF01D1D1D),
    // Values extracted from navigation bar. For toolbar or tabbar the dark color is 0xF0161616.
  ),
  CupertinoColors.systemBackground,
25
  false,
26 27
  _CupertinoTextThemeDefaults(CupertinoColors.label, CupertinoColors.inactiveGray),
);
xster's avatar
xster committed
28 29 30 31 32 33 34 35 36 37

/// Applies a visual styling theme to descendant Cupertino widgets.
///
/// Affects the color and text styles of Cupertino widgets whose styling
/// are not overridden when constructing the respective widgets instances.
///
/// Descendant widgets can retrieve the current [CupertinoThemeData] by calling
/// [CupertinoTheme.of]. An [InheritedWidget] dependency is created when
/// an ancestor [CupertinoThemeData] is retrieved via [CupertinoTheme.of].
///
38 39 40
/// The [CupertinoTheme] widget implies an [IconTheme] widget, whose
/// [IconTheme.data] has the same color as [CupertinoThemeData.primaryColor]
///
xster's avatar
xster committed
41 42 43
/// See also:
///
///  * [CupertinoThemeData], specifies the theme's visual styling.
44 45
///  * [CupertinoApp], which will automatically add a [CupertinoTheme] based on the
///    value of [CupertinoApp.theme].
xster's avatar
xster committed
46 47
///  * [Theme], a Material theme which will automatically add a [CupertinoTheme]
///    with a [CupertinoThemeData] derived from the Material [ThemeData].
48
class CupertinoTheme extends StatelessWidget {
xster's avatar
xster committed
49 50
  /// Creates a [CupertinoTheme] to change descendant Cupertino widgets' styling.
  const CupertinoTheme({
51
    super.key,
52 53
    required this.data,
    required this.child,
54
  });
xster's avatar
xster committed
55 56 57 58

  /// The [CupertinoThemeData] styling for this theme.
  final CupertinoThemeData data;

59 60 61
  /// Retrieves the [CupertinoThemeData] from the closest ancestor [CupertinoTheme]
  /// widget, or a default [CupertinoThemeData] if no [CupertinoTheme] ancestor
  /// exists.
xster's avatar
xster committed
62
  ///
63 64
  /// Resolves all the colors defined in that [CupertinoThemeData] against the
  /// given [BuildContext] on a best-effort basis.
xster's avatar
xster committed
65
  static CupertinoThemeData of(BuildContext context) {
66
    final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>();
67
    return (inheritedTheme?.theme.data ?? const CupertinoThemeData()).resolveFrom(context);
68 69
  }

70 71
  /// Retrieves the [Brightness] to use for descendant Cupertino widgets, based
  /// on the value of [CupertinoThemeData.brightness] in the given [context].
72
  ///
73
  /// If no [CupertinoTheme] can be found in the given [context], or its `brightness`
74
  /// is null, it will fall back to [MediaQueryData.platformBrightness].
75
  ///
76
  /// Throws an exception if no valid [CupertinoTheme] or [MediaQuery] widgets
77
  /// exist in the ancestry tree.
78 79 80
  ///
  /// See also:
  ///
81 82
  /// * [maybeBrightnessOf], which returns null if no valid [CupertinoTheme] or
  ///   [MediaQuery] exists, instead of throwing.
83 84
  /// * [CupertinoThemeData.brightness], the property takes precedence over
  ///   [MediaQueryData.platformBrightness] for descendant Cupertino widgets.
85
  static Brightness brightnessOf(BuildContext context) {
86
    final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>();
87
    return inheritedTheme?.theme.data.brightness ?? MediaQuery.platformBrightnessOf(context);
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  }

  /// Retrieves the [Brightness] to use for descendant Cupertino widgets, based
  /// on the value of [CupertinoThemeData.brightness] in the given [context].
  ///
  /// If no [CupertinoTheme] can be found in the given [context], it will fall
  /// back to [MediaQueryData.platformBrightness].
  ///
  /// Returns null if no valid [CupertinoTheme] or [MediaQuery] widgets exist in
  /// the ancestry tree.
  ///
  /// See also:
  ///
  /// * [CupertinoThemeData.brightness], the property takes precedence over
  ///   [MediaQueryData.platformBrightness] for descendant Cupertino widgets.
  /// * [brightnessOf], which throws if no valid [CupertinoTheme] or
  ///   [MediaQuery] exists, instead of returning null.
  static Brightness? maybeBrightnessOf(BuildContext context) {
    final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>();
107
    return inheritedTheme?.theme.data.brightness ?? MediaQuery.maybePlatformBrightnessOf(context);
108 109 110 111
  }

  /// The widget below this widget in the tree.
  ///
112
  /// {@macro flutter.widgets.ProxyWidget.child}
113 114 115 116
  final Widget child;

  @override
  Widget build(BuildContext context) {
117
    return _InheritedCupertinoTheme(
118 119
      theme: this,
      child: IconTheme(
120
        data: CupertinoIconThemeData(color: data.primaryColor),
121
        child: child,
122
      ),
123
    );
xster's avatar
xster committed
124
  }
125 126 127 128 129 130

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    data.debugFillProperties(properties);
  }
xster's avatar
xster committed
131 132
}

133 134
class _InheritedCupertinoTheme extends InheritedWidget {
  const _InheritedCupertinoTheme({
135
    required this.theme,
136
    required super.child,
137
  });
138 139 140 141 142 143 144

  final CupertinoTheme theme;

  @override
  bool updateShouldNotify(_InheritedCupertinoTheme old) => theme.data != old.theme.data;
}

xster's avatar
xster committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
/// Styling specifications for a [CupertinoTheme].
///
/// All constructor parameters can be null, in which case a
/// [CupertinoColors.activeBlue] based default iOS theme styling is used.
///
/// Parameters can also be partially specified, in which case some parameters
/// will cascade down to other dependent parameters to create a cohesive
/// visual effect. For instance, if a [primaryColor] is specified, it would
/// cascade down to affect some fonts in [textTheme] if [textTheme] is not
/// specified.
///
/// See also:
///
///  * [CupertinoTheme], in which this [CupertinoThemeData] is inserted.
///  * [ThemeData], a Material equivalent that also configures Cupertino
///    styling via a [CupertinoThemeData] subclass [MaterialBasedCupertinoThemeData].
@immutable
162
class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable {
163
  /// Creates a [CupertinoTheme] styling specification.
xster's avatar
xster committed
164 165 166
  ///
  /// Unspecified parameters default to a reasonable iOS default style.
  const CupertinoThemeData({
167 168 169 170 171 172
    Brightness? brightness,
    Color? primaryColor,
    Color? primaryContrastingColor,
    CupertinoTextThemeData? textTheme,
    Color? barBackgroundColor,
    Color? scaffoldBackgroundColor,
173
    bool? applyThemeToAll,
xster's avatar
xster committed
174 175 176 177 178 179 180
  }) : this.raw(
        brightness,
        primaryColor,
        primaryContrastingColor,
        textTheme,
        barBackgroundColor,
        scaffoldBackgroundColor,
181
        applyThemeToAll,
xster's avatar
xster committed
182 183 184 185 186 187 188 189
      );

  /// Same as the default constructor but with positional arguments to avoid
  /// forgetting any and to specify all arguments.
  ///
  /// Used by subclasses to get the superclass's defaulting behaviors.
  @protected
  const CupertinoThemeData.raw(
190 191 192 193 194 195
    Brightness? brightness,
    Color? primaryColor,
    Color? primaryContrastingColor,
    CupertinoTextThemeData? textTheme,
    Color? barBackgroundColor,
    Color? scaffoldBackgroundColor,
196
    bool? applyThemeToAll,
197 198 199 200 201 202 203
  ) : this._rawWithDefaults(
    brightness,
    primaryColor,
    primaryContrastingColor,
    textTheme,
    barBackgroundColor,
    scaffoldBackgroundColor,
204
    applyThemeToAll,
205 206 207 208
    _kDefaultTheme,
  );

  const CupertinoThemeData._rawWithDefaults(
209 210 211 212 213 214
    Brightness? brightness,
    Color? primaryColor,
    Color? primaryContrastingColor,
    CupertinoTextThemeData? textTheme,
    Color? barBackgroundColor,
    Color? scaffoldBackgroundColor,
215
    bool? applyThemeToAll,
216
    this._defaults,
217 218 219 220 221 222 223
  ) : super(
    brightness: brightness,
    primaryColor: primaryColor,
    primaryContrastingColor: primaryContrastingColor,
    textTheme: textTheme,
    barBackgroundColor: barBackgroundColor,
    scaffoldBackgroundColor: scaffoldBackgroundColor,
224
    applyThemeToAll: applyThemeToAll,
xster's avatar
xster committed
225 226
  );

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
  final _CupertinoThemeDefaults _defaults;

  @override
  Color get primaryColor => super.primaryColor ?? _defaults.primaryColor;

  @override
  Color get primaryContrastingColor => super.primaryContrastingColor ?? _defaults.primaryContrastingColor;

  @override
  CupertinoTextThemeData get textTheme {
    return super.textTheme ?? _defaults.textThemeDefaults.createDefaults(primaryColor: primaryColor);
  }

  @override
  Color get barBackgroundColor => super.barBackgroundColor ?? _defaults.barBackgroundColor;

  @override
  Color get scaffoldBackgroundColor => super.scaffoldBackgroundColor ?? _defaults.scaffoldBackgroundColor;

246 247 248
  @override
  bool get applyThemeToAll => super.applyThemeToAll ?? _defaults.applyThemeToAll;

249 250 251 252 253 254 255 256 257
  @override
  NoDefaultCupertinoThemeData noDefault() {
    return NoDefaultCupertinoThemeData(
      brightness: super.brightness,
      primaryColor: super.primaryColor,
      primaryContrastingColor: super.primaryContrastingColor,
      textTheme: super.textTheme,
      barBackgroundColor: super.barBackgroundColor,
      scaffoldBackgroundColor: super.scaffoldBackgroundColor,
258
      applyThemeToAll: super.applyThemeToAll,
259 260 261 262
    );
  }

  @override
263 264
  CupertinoThemeData resolveFrom(BuildContext context) {
    Color? convertColor(Color? color) => CupertinoDynamicColor.maybeResolve(color, context);
265 266 267 268 269

    return CupertinoThemeData._rawWithDefaults(
      brightness,
      convertColor(super.primaryColor),
      convertColor(super.primaryContrastingColor),
270
      super.textTheme?.resolveFrom(context),
271 272
      convertColor(super.barBackgroundColor),
      convertColor(super.scaffoldBackgroundColor),
273
      applyThemeToAll,
274
      _defaults.resolveFrom(context, super.textTheme == null),
275 276 277 278 279 280 281 282 283 284 285
    );
  }

  @override
  CupertinoThemeData copyWith({
    Brightness? brightness,
    Color? primaryColor,
    Color? primaryContrastingColor,
    CupertinoTextThemeData? textTheme,
    Color? barBackgroundColor,
    Color? scaffoldBackgroundColor,
286
    bool? applyThemeToAll,
287 288 289 290 291 292 293 294
  }) {
    return CupertinoThemeData._rawWithDefaults(
      brightness ?? super.brightness,
      primaryColor ?? super.primaryColor,
      primaryContrastingColor ?? super.primaryContrastingColor,
      textTheme ?? super.textTheme,
      barBackgroundColor ?? super.barBackgroundColor,
      scaffoldBackgroundColor ?? super.scaffoldBackgroundColor,
295
      applyThemeToAll ?? super.applyThemeToAll,
296 297 298 299 300 301 302 303 304 305 306 307 308
      _defaults,
    );
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    const CupertinoThemeData defaultData = CupertinoThemeData();
    properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: null));
    properties.add(createCupertinoColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor));
    properties.add(createCupertinoColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor));
    properties.add(createCupertinoColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor));
    properties.add(createCupertinoColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor));
309
    properties.add(DiagnosticsProperty<bool>('applyThemeToAll', applyThemeToAll, defaultValue: defaultData.applyThemeToAll));
310 311
    textTheme.debugFillProperties(properties);
  }
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

  @override
  bool operator == (Object other) {
    if (identical(this, other)) {
      return true;
    }
    if (other.runtimeType != runtimeType) {
      return false;
    }
    return other is CupertinoThemeData
      && 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,
  );
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
}

/// Styling specifications for a cupertino theme without default values for
/// unspecified properties.
///
/// Unlike [CupertinoThemeData] instances of this class do not return default
/// values for properties that have been left unspecified in the constructor.
/// Instead, unspecified properties will return null. This is used by
/// Material's [ThemeData.cupertinoOverrideTheme].
///
/// See also:
///
///  * [CupertinoThemeData], which uses reasonable default values for
///    unspecified theme properties.
class NoDefaultCupertinoThemeData {
  /// Creates a [NoDefaultCupertinoThemeData] styling specification.
  ///
  /// Unspecified properties default to null.
  const NoDefaultCupertinoThemeData({
    this.brightness,
    this.primaryColor,
    this.primaryContrastingColor,
    this.textTheme,
    this.barBackgroundColor,
    this.scaffoldBackgroundColor,
366
    this.applyThemeToAll,
367
  });
xster's avatar
xster committed
368

369
  /// The brightness override for Cupertino descendants.
xster's avatar
xster committed
370
  ///
371 372 373
  /// Defaults to null. If a non-null [Brightness] is specified, the value will
  /// take precedence over the ambient [MediaQueryData.platformBrightness], when
  /// determining the brightness of descendant Cupertino widgets.
xster's avatar
xster committed
374 375
  ///
  /// If coming from a Material [Theme] and unspecified, [brightness] will be
376
  /// derived from the Material [ThemeData]'s [brightness].
377 378 379
  ///
  /// See also:
  ///
380 381
  ///  * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers
  ///    [brightness] to its Material [Theme] parent if it's unspecified.
382 383 384
  ///
  ///  * [CupertinoTheme.brightnessOf], a method used to retrieve the overall
  ///    [Brightness] from a [BuildContext], for Cupertino widgets.
385
  final Brightness? brightness;
xster's avatar
xster committed
386 387 388 389

  /// A color used on interactive elements of the theme.
  ///
  /// This color is generally used on text and icons in buttons and tappable
390
  /// elements. Defaults to [CupertinoColors.activeBlue].
xster's avatar
xster committed
391 392 393 394 395 396
  ///
  /// If coming from a Material [Theme] and unspecified, [primaryColor] will be
  /// derived from the Material [ThemeData]'s `colorScheme.primary`. However, in
  /// iOS styling, the [primaryColor] is more sparsely used than in Material
  /// Design where the [primaryColor] can appear on non-interactive surfaces like
  /// the [AppBar] background, [TextField] borders etc.
397 398 399
  ///
  /// See also:
  ///
400 401
  ///  * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers
  ///    [primaryColor] to its Material [Theme] parent if it's unspecified.
402
  final Color? primaryColor;
xster's avatar
xster committed
403

404
  /// A color that must be easy to see when rendered on a [primaryColor] background.
xster's avatar
xster committed
405 406 407 408 409 410
  ///
  /// For example, this color is used for a [CupertinoButton]'s text and icons
  /// when the button's background is [primaryColor].
  ///
  /// If coming from a Material [Theme] and unspecified, [primaryContrastingColor]
  /// will be derived from the Material [ThemeData]'s `colorScheme.onPrimary`.
411 412 413
  ///
  /// See also:
  ///
414 415
  ///  * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers
  ///    [primaryContrastingColor] to its Material [Theme] parent if it's unspecified.
416
  final Color? primaryContrastingColor;
xster's avatar
xster committed
417 418 419

  /// Text styles used by Cupertino widgets.
  ///
420
  /// Derived from [primaryColor] if unspecified.
421
  final CupertinoTextThemeData? textTheme;
xster's avatar
xster committed
422 423 424

  /// Background color of the top nav bar and bottom tab bar.
  ///
425 426
  /// Defaults to a light gray in light mode, or a dark translucent gray color in
  /// dark mode.
427
  final Color? barBackgroundColor;
xster's avatar
xster committed
428 429 430

  /// Background color of the scaffold.
  ///
431
  /// Defaults to [CupertinoColors.systemBackground].
432
  final Color? scaffoldBackgroundColor;
xster's avatar
xster committed
433

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
  /// Flag to apply this theme to all descendant Cupertino widgets.
  ///
  /// Certain Cupertino widgets previously didn't use theming, matching past
  /// versions of iOS. For example, [CupertinoSwitch]s always used
  /// [CupertinoColors.systemGreen] when active.
  ///
  /// Today, however, these widgets can indeed be themed on iOS. Moreover on
  /// macOS, the accent color is reflected in these widgets. Turning this flag
  /// on ensures that descendant Cupertino widgets will be themed accordingly.
  ///
  /// This flag currently applies to the following widgets:
  /// - [CupertinoSwitch] & [Switch.adaptive]
  ///
  /// Defaults to false.
  final bool? applyThemeToAll;

450 451
  /// Returns an instance of the theme data whose property getters only return
  /// the construction time specifications with no derived values.
xster's avatar
xster committed
452 453 454
  ///
  /// Used in Material themes to let unspecified properties fallback to Material
  /// theme properties instead of iOS defaults.
455
  NoDefaultCupertinoThemeData noDefault() => this;
xster's avatar
xster committed
456

457
  /// Returns a new theme data with all its colors resolved against the
458
  /// given [BuildContext].
459
  ///
460 461
  /// Called by [CupertinoTheme.of] to resolve colors defined in the retrieved
  /// [CupertinoThemeData].
462
  @protected
463 464
  NoDefaultCupertinoThemeData resolveFrom(BuildContext context) {
    Color? convertColor(Color? color) => CupertinoDynamicColor.maybeResolve(color, context);
465

466 467 468 469
    return NoDefaultCupertinoThemeData(
      brightness: brightness,
      primaryColor: convertColor(primaryColor),
      primaryContrastingColor: convertColor(primaryContrastingColor),
470
      textTheme: textTheme?.resolveFrom(context),
471 472
      barBackgroundColor: convertColor(barBackgroundColor),
      scaffoldBackgroundColor: convertColor(scaffoldBackgroundColor),
473
      applyThemeToAll: applyThemeToAll,
474 475 476
    );
  }

477
  /// Creates a copy of the theme data with specified attributes overridden.
xster's avatar
xster committed
478 479
  ///
  /// Only the current instance's specified attributes are copied instead of
480 481 482 483
  /// derived values. For instance, if the current [textTheme] is implied from
  /// the current [primaryColor] because it was not specified, copying with a
  /// different [primaryColor] will also change the copy's implied [textTheme].
  NoDefaultCupertinoThemeData copyWith({
484 485 486 487 488 489
    Brightness? brightness,
    Color? primaryColor,
    Color? primaryContrastingColor,
    CupertinoTextThemeData? textTheme,
    Color? barBackgroundColor ,
    Color? scaffoldBackgroundColor,
490
    bool? applyThemeToAll,
491
  }) {
492 493 494 495 496 497 498
    return NoDefaultCupertinoThemeData(
      brightness: brightness ?? this.brightness,
      primaryColor: primaryColor ?? this.primaryColor,
      primaryContrastingColor: primaryContrastingColor ?? this.primaryContrastingColor,
      textTheme: textTheme ?? this.textTheme,
      barBackgroundColor: barBackgroundColor ?? this.barBackgroundColor,
      scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor,
499
      applyThemeToAll: applyThemeToAll ?? this.applyThemeToAll,
500 501
    );
  }
xster's avatar
xster committed
502
}
503 504 505 506 507 508 509 510 511

@immutable
class _CupertinoThemeDefaults {
  const _CupertinoThemeDefaults(
    this.brightness,
    this.primaryColor,
    this.primaryContrastingColor,
    this.barBackgroundColor,
    this.scaffoldBackgroundColor,
512
    this.applyThemeToAll,
513 514 515
    this.textThemeDefaults,
  );

516
  final Brightness? brightness;
517 518 519 520
  final Color primaryColor;
  final Color primaryContrastingColor;
  final Color barBackgroundColor;
  final Color scaffoldBackgroundColor;
521
  final bool applyThemeToAll;
522 523
  final _CupertinoTextThemeDefaults textThemeDefaults;

524 525
  _CupertinoThemeDefaults resolveFrom(BuildContext context, bool resolveTextTheme) {
    Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context);
526 527 528 529 530 531 532

    return _CupertinoThemeDefaults(
      brightness,
      convertColor(primaryColor),
      convertColor(primaryContrastingColor),
      convertColor(barBackgroundColor),
      convertColor(scaffoldBackgroundColor),
533
      applyThemeToAll,
534
      resolveTextTheme ? textThemeDefaults.resolveFrom(context) : textThemeDefaults,
535 536 537 538 539 540 541 542 543 544 545 546 547 548
    );
  }
}

@immutable
class _CupertinoTextThemeDefaults {
  const _CupertinoTextThemeDefaults(
    this.labelColor,
    this.inactiveGray,
  );

  final Color labelColor;
  final Color inactiveGray;

549
  _CupertinoTextThemeDefaults resolveFrom(BuildContext context) {
550
    return _CupertinoTextThemeDefaults(
551 552
      CupertinoDynamicColor.resolve(labelColor, context),
      CupertinoDynamicColor.resolve(inactiveGray, context),
553 554 555
    );
  }

556
  CupertinoTextThemeData createDefaults({ required Color primaryColor }) {
557 558 559 560 561 562 563 564 565 566 567 568 569
    return _DefaultCupertinoTextThemeData(
      primaryColor: primaryColor,
      labelColor: labelColor,
      inactiveGray: inactiveGray,
    );
  }
}

// CupertinoTextThemeData with no text styles explicitly specified.
// The implementation of this class may need to be updated when any of the default
// text styles changes.
class _DefaultCupertinoTextThemeData extends CupertinoTextThemeData {
  const _DefaultCupertinoTextThemeData({
570 571
    required this.labelColor,
    required this.inactiveGray,
572
    required super.primaryColor,
573
  });
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595

  final Color labelColor;
  final Color inactiveGray;

  @override
  TextStyle get textStyle => super.textStyle.copyWith(color: labelColor);

  @override
  TextStyle get tabLabelTextStyle => super.tabLabelTextStyle.copyWith(color: inactiveGray);

  @override
  TextStyle get navTitleTextStyle => super.navTitleTextStyle.copyWith(color: labelColor);

  @override
  TextStyle get navLargeTitleTextStyle => super.navLargeTitleTextStyle.copyWith(color: labelColor);

  @override
  TextStyle get pickerTextStyle => super.pickerTextStyle.copyWith(color: labelColor);

  @override
  TextStyle get dateTimePickerTextStyle => super.dateTimePickerTextStyle.copyWith(color: labelColor);
}