ThemeData constructor

ThemeData(
  1. {Brightness brightness,
  2. VisualDensity visualDensity,
  3. MaterialColor primarySwatch,
  4. Color primaryColor,
  5. Brightness primaryColorBrightness,
  6. Color primaryColorLight,
  7. Color primaryColorDark,
  8. Color accentColor,
  9. Brightness accentColorBrightness,
  10. Color canvasColor,
  11. Color shadowColor,
  12. Color scaffoldBackgroundColor,
  13. Color bottomAppBarColor,
  14. Color cardColor,
  15. Color dividerColor,
  16. Color focusColor,
  17. Color hoverColor,
  18. Color highlightColor,
  19. Color splashColor,
  20. InteractiveInkFeatureFactory splashFactory,
  21. Color selectedRowColor,
  22. Color unselectedWidgetColor,
  23. Color disabledColor,
  24. Color buttonColor,
  25. ButtonThemeData buttonTheme,
  26. ToggleButtonsThemeData toggleButtonsTheme,
  27. Color secondaryHeaderColor,
  28. Color textSelectionColor,
  29. Color cursorColor,
  30. Color textSelectionHandleColor,
  31. Color backgroundColor,
  32. Color dialogBackgroundColor,
  33. Color indicatorColor,
  34. Color hintColor,
  35. Color errorColor,
  36. Color toggleableActiveColor,
  37. String fontFamily,
  38. TextTheme textTheme,
  39. TextTheme primaryTextTheme,
  40. TextTheme accentTextTheme,
  41. InputDecorationTheme inputDecorationTheme,
  42. IconThemeData iconTheme,
  43. IconThemeData primaryIconTheme,
  44. IconThemeData accentIconTheme,
  45. SliderThemeData sliderTheme,
  46. TabBarTheme tabBarTheme,
  47. TooltipThemeData tooltipTheme,
  48. CardTheme cardTheme,
  49. ChipThemeData chipTheme,
  50. TargetPlatform platform,
  51. MaterialTapTargetSize materialTapTargetSize,
  52. bool applyElevationOverlayColor,
  53. PageTransitionsTheme pageTransitionsTheme,
  54. AppBarTheme appBarTheme,
  55. BottomAppBarTheme bottomAppBarTheme,
  56. ColorScheme colorScheme,
  57. DialogTheme dialogTheme,
  58. FloatingActionButtonThemeData floatingActionButtonTheme,
  59. NavigationRailThemeData navigationRailTheme,
  60. Typography typography,
  61. CupertinoThemeData cupertinoOverrideTheme,
  62. SnackBarThemeData snackBarTheme,
  63. BottomSheetThemeData bottomSheetTheme,
  64. PopupMenuThemeData popupMenuTheme,
  65. MaterialBannerThemeData bannerTheme,
  66. DividerThemeData dividerTheme,
  67. ButtonBarThemeData buttonBarTheme,
  68. BottomNavigationBarThemeData bottomNavigationBarTheme,
  69. TimePickerThemeData timePickerTheme,
  70. TextButtonThemeData textButtonTheme,
  71. ElevatedButtonThemeData elevatedButtonTheme,
  72. OutlinedButtonThemeData outlinedButtonTheme,
  73. TextSelectionThemeData textSelectionTheme,
  74. DataTableThemeData dataTableTheme,
  75. bool fixTextFieldOutlineLabel,
  76. bool useTextSelectionTheme}
)

Create a ThemeData that's used to configure a Theme.

Typically, only the brightness, primaryColor, or primarySwatch are specified. That pair of values are used to construct the colorScheme.

The colorScheme and textTheme are used by the Material components to compute default values for visual properties. The API documentation for each component widget explains exactly how the defaults are computed.

The textTheme TextStyle colors are black if the color scheme's brightness is Brightness.light, and white for Brightness.dark.

To override the appearance of specific components, provide a component theme parameter like sliderTheme, toggleButtonsTheme, or bottomNavigationBarTheme.

See also:

Implementation

factory ThemeData({
  Brightness brightness,
  VisualDensity visualDensity,
  MaterialColor primarySwatch,
  Color primaryColor,
  Brightness primaryColorBrightness,
  Color primaryColorLight,
  Color primaryColorDark,
  Color accentColor,
  Brightness accentColorBrightness,
  Color canvasColor,
  Color shadowColor,
  Color scaffoldBackgroundColor,
  Color bottomAppBarColor,
  Color cardColor,
  Color dividerColor,
  Color focusColor,
  Color hoverColor,
  Color highlightColor,
  Color splashColor,
  InteractiveInkFeatureFactory splashFactory,
  Color selectedRowColor,
  Color unselectedWidgetColor,
  Color disabledColor,
  Color buttonColor,
  ButtonThemeData buttonTheme,
  ToggleButtonsThemeData toggleButtonsTheme,
  Color secondaryHeaderColor,
  Color textSelectionColor,
  Color cursorColor,
  Color textSelectionHandleColor,
  Color backgroundColor,
  Color dialogBackgroundColor,
  Color indicatorColor,
  Color hintColor,
  Color errorColor,
  Color toggleableActiveColor,
  String fontFamily,
  TextTheme textTheme,
  TextTheme primaryTextTheme,
  TextTheme accentTextTheme,
  InputDecorationTheme inputDecorationTheme,
  IconThemeData iconTheme,
  IconThemeData primaryIconTheme,
  IconThemeData accentIconTheme,
  SliderThemeData sliderTheme,
  TabBarTheme tabBarTheme,
  TooltipThemeData tooltipTheme,
  CardTheme cardTheme,
  ChipThemeData chipTheme,
  TargetPlatform platform,
  MaterialTapTargetSize materialTapTargetSize,
  bool applyElevationOverlayColor,
  PageTransitionsTheme pageTransitionsTheme,
  AppBarTheme appBarTheme,
  BottomAppBarTheme bottomAppBarTheme,
  ColorScheme colorScheme,
  DialogTheme dialogTheme,
  FloatingActionButtonThemeData floatingActionButtonTheme,
  NavigationRailThemeData navigationRailTheme,
  Typography typography,
  CupertinoThemeData cupertinoOverrideTheme,
  SnackBarThemeData snackBarTheme,
  BottomSheetThemeData bottomSheetTheme,
  PopupMenuThemeData popupMenuTheme,
  MaterialBannerThemeData bannerTheme,
  DividerThemeData dividerTheme,
  ButtonBarThemeData buttonBarTheme,
  BottomNavigationBarThemeData bottomNavigationBarTheme,
  TimePickerThemeData timePickerTheme,
  TextButtonThemeData textButtonTheme,
  ElevatedButtonThemeData elevatedButtonTheme,
  OutlinedButtonThemeData outlinedButtonTheme,
  TextSelectionThemeData textSelectionTheme,
  DataTableThemeData dataTableTheme,
  bool fixTextFieldOutlineLabel,
  bool useTextSelectionTheme,
}) {
  assert(colorScheme?.brightness == null || brightness == null || colorScheme.brightness == brightness);
  final Brightness _brightness = brightness ?? colorScheme?.brightness ?? Brightness.light;
  final bool isDark = _brightness == Brightness.dark;
  visualDensity ??= const VisualDensity();
  primarySwatch ??= Colors.blue;
  primaryColor ??= isDark ? Colors.grey[900] : primarySwatch;
  primaryColorBrightness ??= estimateBrightnessForColor(primaryColor);
  primaryColorLight ??= isDark ? Colors.grey[500] : primarySwatch[100];
  primaryColorDark ??= isDark ? Colors.black : primarySwatch[700];
  final bool primaryIsDark = primaryColorBrightness == Brightness.dark;
  toggleableActiveColor ??= isDark ? Colors.tealAccent[200] : (accentColor ?? primarySwatch[600]);
  accentColor ??= isDark ? Colors.tealAccent[200] : primarySwatch[500];
  accentColorBrightness ??= estimateBrightnessForColor(accentColor);
  final bool accentIsDark = accentColorBrightness == Brightness.dark;
  canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50];
  shadowColor ??= Colors.black;
  scaffoldBackgroundColor ??= canvasColor;
  bottomAppBarColor ??= isDark ? Colors.grey[800] : Colors.white;
  cardColor ??= isDark ? Colors.grey[800] : Colors.white;
  dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000);

  // Create a ColorScheme that is backwards compatible as possible
  // with the existing default ThemeData color values.
  colorScheme ??= ColorScheme.fromSwatch(
    primarySwatch: primarySwatch,
    primaryColorDark: primaryColorDark,
    accentColor: accentColor,
    cardColor: cardColor,
    backgroundColor: backgroundColor,
    errorColor: errorColor,
    brightness: _brightness,
  );

  splashFactory ??= InkSplash.splashFactory;
  selectedRowColor ??= Colors.grey[100];
  unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
  // Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
  secondaryHeaderColor ??= isDark ? Colors.grey[700] : primarySwatch[50];
  textSelectionColor ??= isDark ? accentColor : primarySwatch[200];
  cursorColor = cursorColor ?? const Color.fromRGBO(66, 133, 244, 1.0);
  textSelectionHandleColor ??= isDark ? Colors.tealAccent[400] : primarySwatch[300];
  backgroundColor ??= isDark ? Colors.grey[700] : primarySwatch[200];
  dialogBackgroundColor ??= isDark ? Colors.grey[800] : Colors.white;
  indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor;
  hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6);
  errorColor ??= Colors.red[700];
  inputDecorationTheme ??= const InputDecorationTheme();
  pageTransitionsTheme ??= const PageTransitionsTheme();
  primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
  accentIconTheme ??= accentIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
  iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black87);
  platform ??= defaultTargetPlatform;
  typography ??= Typography.material2014(platform: platform);
  TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
  TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;
  TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;
  if (fontFamily != null) {
    defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily);
    defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily);
    defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily);
  }
  textTheme = defaultTextTheme.merge(textTheme);
  primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
  accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme);
  materialTapTargetSize ??= MaterialTapTargetSize.padded;
  applyElevationOverlayColor ??= false;

  // Used as the default color (fill color) for RaisedButtons. Computing the
  // default for ButtonThemeData for the sake of backwards compatibility.
  buttonColor ??= isDark ? primarySwatch[600] : Colors.grey[300];
  focusColor ??= isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.12);
  hoverColor ??= isDark ? Colors.white.withOpacity(0.04) : Colors.black.withOpacity(0.04);
  buttonTheme ??= ButtonThemeData(
    colorScheme: colorScheme,
    buttonColor: buttonColor,
    disabledColor: disabledColor,
    focusColor: focusColor,
    hoverColor: hoverColor,
    highlightColor: highlightColor,
    splashColor: splashColor,
    materialTapTargetSize: materialTapTargetSize,
  );
  toggleButtonsTheme ??= const ToggleButtonsThemeData();
  disabledColor ??= isDark ? Colors.white38 : Colors.black38;
  highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor;
  splashColor ??= isDark ? _kDarkThemeSplashColor : _kLightThemeSplashColor;

  sliderTheme ??= const SliderThemeData();
  tabBarTheme ??= const TabBarTheme();
  tooltipTheme ??= const TooltipThemeData();
  appBarTheme ??= const AppBarTheme();
  bottomAppBarTheme ??= const BottomAppBarTheme();
  cardTheme ??= const CardTheme();
  chipTheme ??= ChipThemeData.fromDefaults(
    secondaryColor: primaryColor,
    brightness: colorScheme.brightness,
    labelStyle: textTheme.bodyText1,
  );
  dialogTheme ??= const DialogTheme();
  floatingActionButtonTheme ??= const FloatingActionButtonThemeData();
  navigationRailTheme ??= const NavigationRailThemeData();
  cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
  snackBarTheme ??= const SnackBarThemeData();
  bottomSheetTheme ??= const BottomSheetThemeData();
  popupMenuTheme ??= const PopupMenuThemeData();
  bannerTheme ??= const MaterialBannerThemeData();
  dividerTheme ??= const DividerThemeData();
  buttonBarTheme ??= const ButtonBarThemeData();
  bottomNavigationBarTheme ??= const BottomNavigationBarThemeData();
  timePickerTheme ??= const TimePickerThemeData();
  textButtonTheme ??= const TextButtonThemeData();
  elevatedButtonTheme ??= const ElevatedButtonThemeData();
  outlinedButtonTheme ??= const OutlinedButtonThemeData();
  textSelectionTheme ??= const TextSelectionThemeData();
  dataTableTheme ??= const DataTableThemeData();

  fixTextFieldOutlineLabel ??= false;
  useTextSelectionTheme ??= false;

  return ThemeData.raw(
    visualDensity: visualDensity,
    primaryColor: primaryColor,
    primaryColorBrightness: primaryColorBrightness,
    primaryColorLight: primaryColorLight,
    primaryColorDark: primaryColorDark,
    accentColor: accentColor,
    accentColorBrightness: accentColorBrightness,
    canvasColor: canvasColor,
    shadowColor: shadowColor,
    scaffoldBackgroundColor: scaffoldBackgroundColor,
    bottomAppBarColor: bottomAppBarColor,
    cardColor: cardColor,
    dividerColor: dividerColor,
    focusColor: focusColor,
    hoverColor: hoverColor,
    highlightColor: highlightColor,
    splashColor: splashColor,
    splashFactory: splashFactory,
    selectedRowColor: selectedRowColor,
    unselectedWidgetColor: unselectedWidgetColor,
    disabledColor: disabledColor,
    buttonTheme: buttonTheme,
    buttonColor: buttonColor,
    toggleButtonsTheme: toggleButtonsTheme,
    toggleableActiveColor: toggleableActiveColor,
    secondaryHeaderColor: secondaryHeaderColor,
    textSelectionColor: textSelectionColor,
    cursorColor: cursorColor,
    textSelectionHandleColor: textSelectionHandleColor,
    backgroundColor: backgroundColor,
    dialogBackgroundColor: dialogBackgroundColor,
    indicatorColor: indicatorColor,
    hintColor: hintColor,
    errorColor: errorColor,
    textTheme: textTheme,
    primaryTextTheme: primaryTextTheme,
    accentTextTheme: accentTextTheme,
    inputDecorationTheme: inputDecorationTheme,
    iconTheme: iconTheme,
    primaryIconTheme: primaryIconTheme,
    accentIconTheme: accentIconTheme,
    sliderTheme: sliderTheme,
    tabBarTheme: tabBarTheme,
    tooltipTheme: tooltipTheme,
    cardTheme: cardTheme,
    chipTheme: chipTheme,
    platform: platform,
    materialTapTargetSize: materialTapTargetSize,
    applyElevationOverlayColor: applyElevationOverlayColor,
    pageTransitionsTheme: pageTransitionsTheme,
    appBarTheme: appBarTheme,
    bottomAppBarTheme: bottomAppBarTheme,
    colorScheme: colorScheme,
    dialogTheme: dialogTheme,
    floatingActionButtonTheme: floatingActionButtonTheme,
    navigationRailTheme: navigationRailTheme,
    typography: typography,
    cupertinoOverrideTheme: cupertinoOverrideTheme,
    snackBarTheme: snackBarTheme,
    bottomSheetTheme: bottomSheetTheme,
    popupMenuTheme: popupMenuTheme,
    bannerTheme: bannerTheme,
    dividerTheme: dividerTheme,
    buttonBarTheme: buttonBarTheme,
    bottomNavigationBarTheme: bottomNavigationBarTheme,
    timePickerTheme: timePickerTheme,
    textButtonTheme: textButtonTheme,
    elevatedButtonTheme: elevatedButtonTheme,
    outlinedButtonTheme: outlinedButtonTheme,
    textSelectionTheme: textSelectionTheme,
    dataTableTheme: dataTableTheme,
    fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
    useTextSelectionTheme: useTextSelectionTheme,
  );
}