copyWith method Null safety

ThemeData copyWith(
  1. {bool? applyElevationOverlayColor,
  2. NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
  3. Iterable<ThemeExtension>? extensions,
  4. InputDecorationTheme? inputDecorationTheme,
  5. MaterialTapTargetSize? materialTapTargetSize,
  6. PageTransitionsTheme? pageTransitionsTheme,
  7. TargetPlatform? platform,
  8. ScrollbarThemeData? scrollbarTheme,
  9. InteractiveInkFeatureFactory? splashFactory,
  10. bool? useMaterial3,
  11. VisualDensity? visualDensity,
  12. Brightness? brightness,
  13. Color? canvasColor,
  14. Color? cardColor,
  15. ColorScheme? colorScheme,
  16. Color? dialogBackgroundColor,
  17. Color? disabledColor,
  18. Color? dividerColor,
  19. Color? focusColor,
  20. Color? highlightColor,
  21. Color? hintColor,
  22. Color? hoverColor,
  23. Color? indicatorColor,
  24. Color? primaryColor,
  25. Color? primaryColorDark,
  26. Color? primaryColorLight,
  27. Color? scaffoldBackgroundColor,
  28. Color? secondaryHeaderColor,
  29. Color? shadowColor,
  30. Color? splashColor,
  31. Color? unselectedWidgetColor,
  32. IconThemeData? iconTheme,
  33. IconThemeData? primaryIconTheme,
  34. TextTheme? primaryTextTheme,
  35. TextTheme? textTheme,
  36. Typography? typography,
  37. AppBarTheme? appBarTheme,
  38. BadgeThemeData? badgeTheme,
  39. MaterialBannerThemeData? bannerTheme,
  40. BottomAppBarTheme? bottomAppBarTheme,
  41. BottomNavigationBarThemeData? bottomNavigationBarTheme,
  42. BottomSheetThemeData? bottomSheetTheme,
  43. ButtonBarThemeData? buttonBarTheme,
  44. ButtonThemeData? buttonTheme,
  45. CardTheme? cardTheme,
  46. CheckboxThemeData? checkboxTheme,
  47. ChipThemeData? chipTheme,
  48. DataTableThemeData? dataTableTheme,
  49. DialogTheme? dialogTheme,
  50. DividerThemeData? dividerTheme,
  51. DrawerThemeData? drawerTheme,
  52. DropdownMenuThemeData? dropdownMenuTheme,
  53. ElevatedButtonThemeData? elevatedButtonTheme,
  54. ExpansionTileThemeData? expansionTileTheme,
  55. FilledButtonThemeData? filledButtonTheme,
  56. FloatingActionButtonThemeData? floatingActionButtonTheme,
  57. IconButtonThemeData? iconButtonTheme,
  58. ListTileThemeData? listTileTheme,
  59. MenuBarThemeData? menuBarTheme,
  60. MenuButtonThemeData? menuButtonTheme,
  61. MenuThemeData? menuTheme,
  62. NavigationBarThemeData? navigationBarTheme,
  63. NavigationDrawerThemeData? navigationDrawerTheme,
  64. NavigationRailThemeData? navigationRailTheme,
  65. OutlinedButtonThemeData? outlinedButtonTheme,
  66. PopupMenuThemeData? popupMenuTheme,
  67. ProgressIndicatorThemeData? progressIndicatorTheme,
  68. RadioThemeData? radioTheme,
  69. SegmentedButtonThemeData? segmentedButtonTheme,
  70. SliderThemeData? sliderTheme,
  71. SnackBarThemeData? snackBarTheme,
  72. SwitchThemeData? switchTheme,
  73. TabBarTheme? tabBarTheme,
  74. TextButtonThemeData? textButtonTheme,
  75. TextSelectionThemeData? textSelectionTheme,
  76. TimePickerThemeData? timePickerTheme,
  77. ToggleButtonsThemeData? toggleButtonsTheme,
  78. TooltipThemeData? tooltipTheme,
  79. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'For more information, consult the migration guide at ' 'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. ' 'This feature was deprecated after v2.3.0-0.1.pre.') Color? accentColor,
  80. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'For more information, consult the migration guide at ' 'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. ' 'This feature was deprecated after v2.3.0-0.1.pre.') Brightness? accentColorBrightness,
  81. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'For more information, consult the migration guide at ' 'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. ' 'This feature was deprecated after v2.3.0-0.1.pre.') TextTheme? accentTextTheme,
  82. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'For more information, consult the migration guide at ' 'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. ' 'This feature was deprecated after v2.3.0-0.1.pre.') IconThemeData? accentIconTheme,
  83. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'This feature was deprecated after v2.3.0-0.2.pre.') Color? buttonColor,
  84. @Deprecated('This "fix" is now enabled by default. ' 'This feature was deprecated after v2.5.0-1.0.pre.') bool? fixTextFieldOutlineLabel,
  85. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'This feature was deprecated after v2.6.0-11.0.pre.') Brightness? primaryColorBrightness,
  86. @Deprecated('Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' 'This feature was deprecated after v2.13.0-0.0.pre.') AndroidOverscrollIndicator? androidOverscrollIndicator,
  87. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'For more information, consult the migration guide at ' 'https://flutter.dev/docs/release/breaking-changes/toggleable-active-color#migration-guide. ' 'This feature was deprecated after v3.4.0-19.0.pre.') Color? toggleableActiveColor,
  88. @Deprecated('No longer used by the framework, please remove any reference to it. ' 'This feature was deprecated after v3.1.0-0.0.pre.') Color? selectedRowColor,
  89. @Deprecated('Use colorScheme.error instead. ' 'This feature was deprecated after v2.6.0-11.0.pre.') Color? errorColor,
  90. @Deprecated('Use colorScheme.background instead. ' 'This feature was deprecated after v2.6.0-11.0.pre.') Color? backgroundColor,
  91. @Deprecated('Use BottomAppBarTheme.color instead. ' 'This feature was deprecated after v3.3.0-0.6.pre.') Color? bottomAppBarColor}
)

Caches localized themes to speed up the localize method. Creates a copy of this theme but with the given fields replaced with the new values.

The brightness value is applied to the colorScheme.

Implementation

/// Creates a copy of this theme but with the given fields replaced with the new values.
///
/// The [brightness] value is applied to the [colorScheme].
ThemeData copyWith({
  // For the sanity of the reader, make sure these properties are in the same
  // order in every place that they are separated by section comments (e.g.
  // GENERAL CONFIGURATION). Each section except for deprecations should be
  // alphabetical by symbol name.

  // GENERAL CONFIGURATION
  bool? applyElevationOverlayColor,
  NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
  Iterable<ThemeExtension<dynamic>>? extensions,
  InputDecorationTheme? inputDecorationTheme,
  MaterialTapTargetSize? materialTapTargetSize,
  PageTransitionsTheme? pageTransitionsTheme,
  TargetPlatform? platform,
  ScrollbarThemeData? scrollbarTheme,
  InteractiveInkFeatureFactory? splashFactory,
  bool? useMaterial3,
  VisualDensity? visualDensity,
  // COLOR
  // [colorScheme] is the preferred way to configure colors. The other color
  // properties will gradually be phased out, see
  // https://github.com/flutter/flutter/issues/91772.
  Brightness? brightness,
  Color? canvasColor,
  Color? cardColor,
  ColorScheme? colorScheme,
  Color? dialogBackgroundColor,
  Color? disabledColor,
  Color? dividerColor,
  Color? focusColor,
  Color? highlightColor,
  Color? hintColor,
  Color? hoverColor,
  Color? indicatorColor,
  Color? primaryColor,
  Color? primaryColorDark,
  Color? primaryColorLight,
  Color? scaffoldBackgroundColor,
  Color? secondaryHeaderColor,
  Color? shadowColor,
  Color? splashColor,
  Color? unselectedWidgetColor,
  // TYPOGRAPHY & ICONOGRAPHY
  IconThemeData? iconTheme,
  IconThemeData? primaryIconTheme,
  TextTheme? primaryTextTheme,
  TextTheme? textTheme,
  Typography? typography,
  // COMPONENT THEMES
  AppBarTheme? appBarTheme,
  BadgeThemeData? badgeTheme,
  MaterialBannerThemeData? bannerTheme,
  BottomAppBarTheme? bottomAppBarTheme,
  BottomNavigationBarThemeData? bottomNavigationBarTheme,
  BottomSheetThemeData? bottomSheetTheme,
  ButtonBarThemeData? buttonBarTheme,
  ButtonThemeData? buttonTheme,
  CardTheme? cardTheme,
  CheckboxThemeData? checkboxTheme,
  ChipThemeData? chipTheme,
  DataTableThemeData? dataTableTheme,
  DialogTheme? dialogTheme,
  DividerThemeData? dividerTheme,
  DrawerThemeData? drawerTheme,
  DropdownMenuThemeData? dropdownMenuTheme,
  ElevatedButtonThemeData? elevatedButtonTheme,
  ExpansionTileThemeData? expansionTileTheme,
  FilledButtonThemeData? filledButtonTheme,
  FloatingActionButtonThemeData? floatingActionButtonTheme,
  IconButtonThemeData? iconButtonTheme,
  ListTileThemeData? listTileTheme,
  MenuBarThemeData? menuBarTheme,
  MenuButtonThemeData? menuButtonTheme,
  MenuThemeData? menuTheme,
  NavigationBarThemeData? navigationBarTheme,
  NavigationDrawerThemeData? navigationDrawerTheme,
  NavigationRailThemeData? navigationRailTheme,
  OutlinedButtonThemeData? outlinedButtonTheme,
  PopupMenuThemeData? popupMenuTheme,
  ProgressIndicatorThemeData? progressIndicatorTheme,
  RadioThemeData? radioTheme,
  SegmentedButtonThemeData? segmentedButtonTheme,
  SliderThemeData? sliderTheme,
  SnackBarThemeData? snackBarTheme,
  SwitchThemeData? switchTheme,
  TabBarTheme? tabBarTheme,
  TextButtonThemeData? textButtonTheme,
  TextSelectionThemeData? textSelectionTheme,
  TimePickerThemeData? timePickerTheme,
  ToggleButtonsThemeData? toggleButtonsTheme,
  TooltipThemeData? tooltipTheme,
  // DEPRECATED (newest deprecations at the bottom)
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'For more information, consult the migration guide at '
    'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
    'This feature was deprecated after v2.3.0-0.1.pre.',
  )
  Color? accentColor,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'For more information, consult the migration guide at '
    'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
    'This feature was deprecated after v2.3.0-0.1.pre.',
  )
  Brightness? accentColorBrightness,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'For more information, consult the migration guide at '
    'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
    'This feature was deprecated after v2.3.0-0.1.pre.',
  )
  TextTheme? accentTextTheme,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'For more information, consult the migration guide at '
    'https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. '
    'This feature was deprecated after v2.3.0-0.1.pre.',
  )
  IconThemeData? accentIconTheme,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'This feature was deprecated after v2.3.0-0.2.pre.',
  )
  Color? buttonColor,
  @Deprecated(
    'This "fix" is now enabled by default. '
    'This feature was deprecated after v2.5.0-1.0.pre.',
  )
  bool? fixTextFieldOutlineLabel,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'This feature was deprecated after v2.6.0-11.0.pre.',
  )
  Brightness? primaryColorBrightness,
  @Deprecated(
    'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
    'This feature was deprecated after v2.13.0-0.0.pre.'
  )
  AndroidOverscrollIndicator? androidOverscrollIndicator,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'For more information, consult the migration guide at '
    'https://flutter.dev/docs/release/breaking-changes/toggleable-active-color#migration-guide. '
    'This feature was deprecated after v3.4.0-19.0.pre.',
  )
  Color? toggleableActiveColor,
  @Deprecated(
    'No longer used by the framework, please remove any reference to it. '
    'This feature was deprecated after v3.1.0-0.0.pre.',
  )
  Color? selectedRowColor,
  @Deprecated(
    'Use colorScheme.error instead. '
    'This feature was deprecated after v2.6.0-11.0.pre.',
  )
  Color? errorColor,
  @Deprecated(
    'Use colorScheme.background instead. '
    'This feature was deprecated after v2.6.0-11.0.pre.',
  )
  Color? backgroundColor,
  @Deprecated(
    'Use BottomAppBarTheme.color instead. '
    'This feature was deprecated after v3.3.0-0.6.pre.',
  )
  Color? bottomAppBarColor,
}) {
  cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
  return ThemeData.raw(
    // For the sanity of the reader, make sure these properties are in the same
    // order in every place that they are separated by section comments (e.g.
    // GENERAL CONFIGURATION). Each section except for deprecations should be
    // alphabetical by symbol name.

    // GENERAL CONFIGURATION
    applyElevationOverlayColor: applyElevationOverlayColor ?? this.applyElevationOverlayColor,
    cupertinoOverrideTheme: cupertinoOverrideTheme ?? this.cupertinoOverrideTheme,
    extensions: (extensions != null) ? _themeExtensionIterableToMap(extensions) : this.extensions,
    inputDecorationTheme: inputDecorationTheme ?? this.inputDecorationTheme,
    materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize,
    pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme,
    platform: platform ?? this.platform,
    scrollbarTheme: scrollbarTheme ?? this.scrollbarTheme,
    splashFactory: splashFactory ?? this.splashFactory,
    useMaterial3: useMaterial3 ?? this.useMaterial3,
    visualDensity: visualDensity ?? this.visualDensity,
    // COLOR
    canvasColor: canvasColor ?? this.canvasColor,
    cardColor: cardColor ?? this.cardColor,
    colorScheme: (colorScheme ?? this.colorScheme).copyWith(brightness: brightness),
    dialogBackgroundColor: dialogBackgroundColor ?? this.dialogBackgroundColor,
    disabledColor: disabledColor ?? this.disabledColor,
    dividerColor: dividerColor ?? this.dividerColor,
    focusColor: focusColor ?? this.focusColor,
    highlightColor: highlightColor ?? this.highlightColor,
    hintColor: hintColor ?? this.hintColor,
    hoverColor: hoverColor ?? this.hoverColor,
    indicatorColor: indicatorColor ?? this.indicatorColor,
    primaryColor: primaryColor ?? this.primaryColor,
    primaryColorDark: primaryColorDark ?? this.primaryColorDark,
    primaryColorLight: primaryColorLight ?? this.primaryColorLight,
    scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor,
    secondaryHeaderColor: secondaryHeaderColor ?? this.secondaryHeaderColor,
    shadowColor: shadowColor ?? this.shadowColor,
    splashColor: splashColor ?? this.splashColor,
    unselectedWidgetColor: unselectedWidgetColor ?? this.unselectedWidgetColor,
    // TYPOGRAPHY & ICONOGRAPHY
    iconTheme: iconTheme ?? this.iconTheme,
    primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
    primaryTextTheme: primaryTextTheme ?? this.primaryTextTheme,
    textTheme: textTheme ?? this.textTheme,
    typography: typography ?? this.typography,
    // COMPONENT THEMES
    appBarTheme: appBarTheme ?? this.appBarTheme,
    badgeTheme: badgeTheme ?? this.badgeTheme,
    bannerTheme: bannerTheme ?? this.bannerTheme,
    bottomAppBarTheme: bottomAppBarTheme ?? this.bottomAppBarTheme,
    bottomNavigationBarTheme: bottomNavigationBarTheme ?? this.bottomNavigationBarTheme,
    bottomSheetTheme: bottomSheetTheme ?? this.bottomSheetTheme,
    buttonBarTheme: buttonBarTheme ?? this.buttonBarTheme,
    buttonTheme: buttonTheme ?? this.buttonTheme,
    cardTheme: cardTheme ?? this.cardTheme,
    checkboxTheme: checkboxTheme ?? this.checkboxTheme,
    chipTheme: chipTheme ?? this.chipTheme,
    dataTableTheme: dataTableTheme ?? this.dataTableTheme,
    dialogTheme: dialogTheme ?? this.dialogTheme,
    dividerTheme: dividerTheme ?? this.dividerTheme,
    drawerTheme: drawerTheme ?? this.drawerTheme,
    dropdownMenuTheme: dropdownMenuTheme ?? this.dropdownMenuTheme,
    elevatedButtonTheme: elevatedButtonTheme ?? this.elevatedButtonTheme,
    expansionTileTheme: expansionTileTheme ?? this.expansionTileTheme,
    filledButtonTheme: filledButtonTheme ?? this.filledButtonTheme,
    floatingActionButtonTheme: floatingActionButtonTheme ?? this.floatingActionButtonTheme,
    iconButtonTheme: iconButtonTheme ?? this.iconButtonTheme,
    listTileTheme: listTileTheme ?? this.listTileTheme,
    menuBarTheme: menuBarTheme ?? this.menuBarTheme,
    menuButtonTheme: menuButtonTheme ?? this.menuButtonTheme,
    menuTheme: menuTheme ?? this.menuTheme,
    navigationBarTheme: navigationBarTheme ?? this.navigationBarTheme,
    navigationDrawerTheme: navigationDrawerTheme ?? this.navigationDrawerTheme,
    navigationRailTheme: navigationRailTheme ?? this.navigationRailTheme,
    outlinedButtonTheme: outlinedButtonTheme ?? this.outlinedButtonTheme,
    popupMenuTheme: popupMenuTheme ?? this.popupMenuTheme,
    progressIndicatorTheme: progressIndicatorTheme ?? this.progressIndicatorTheme,
    radioTheme: radioTheme ?? this.radioTheme,
    segmentedButtonTheme: segmentedButtonTheme ?? this.segmentedButtonTheme,
    sliderTheme: sliderTheme ?? this.sliderTheme,
    snackBarTheme: snackBarTheme ?? this.snackBarTheme,
    switchTheme: switchTheme ?? this.switchTheme,
    tabBarTheme: tabBarTheme ?? this.tabBarTheme,
    textButtonTheme: textButtonTheme ?? this.textButtonTheme,
    textSelectionTheme: textSelectionTheme ?? this.textSelectionTheme,
    timePickerTheme: timePickerTheme ?? this.timePickerTheme,
    toggleButtonsTheme: toggleButtonsTheme ?? this.toggleButtonsTheme,
    tooltipTheme: tooltipTheme ?? this.tooltipTheme,
    // DEPRECATED (newest deprecations at the bottom)
    accentColor: accentColor ?? _accentColor,
    accentColorBrightness: accentColorBrightness ?? _accentColorBrightness,
    accentTextTheme: accentTextTheme ?? _accentTextTheme,
    accentIconTheme: accentIconTheme ?? _accentIconTheme,
    buttonColor: buttonColor ?? _buttonColor,
    fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? _fixTextFieldOutlineLabel,
    primaryColorBrightness: primaryColorBrightness ?? _primaryColorBrightness,
    androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator,
    toggleableActiveColor: toggleableActiveColor ?? _toggleableActiveColor,
    selectedRowColor: selectedRowColor ?? _selectedRowColor,
    errorColor: errorColor ?? _errorColor,
    backgroundColor: backgroundColor ?? _backgroundColor,
    bottomAppBarColor: bottomAppBarColor ?? _bottomAppBarColor,
  );
}