Create a ThemeData given a set of preferred values.
Default values will be derived for arguments that are omitted.
The most useful values to give are, in order of importance:
-
The desired theme
brightness
. -
The primary color palette (the
primarySwatch
), chosen from one of the swatches defined by the material design spec. This should be one of the maps from the Colors class that do not have "accent" in their name. -
The
accentColor
, sometimes called the secondary color, and, if the accent color is specified, its brightness (accentColorBrightness
), so that the right contrasting text color will be used over the accent color.
See material.google.com/style/color.html for more discussion on how to pick the right colors.
Source
factory ThemeData({ Brightness brightness, Map<int, Color> primarySwatch, Color primaryColor, Brightness primaryColorBrightness, Color accentColor, Brightness accentColorBrightness, Color canvasColor, Color scaffoldBackgroundColor, Color cardColor, Color dividerColor, Color highlightColor, Color splashColor, Color selectedRowColor, Color unselectedWidgetColor, Color disabledColor, Color buttonColor, Color secondaryHeaderColor, Color textSelectionColor, Color textSelectionHandleColor, Color backgroundColor, Color indicatorColor, Color hintColor, Color errorColor, TextTheme textTheme, TextTheme primaryTextTheme, TextTheme accentTextTheme, IconThemeData iconTheme, IconThemeData primaryIconTheme, IconThemeData accentIconTheme, TargetPlatform platform }) { brightness ??= Brightness.light; final bool isDark = brightness == Brightness.dark; primarySwatch ??= Colors.blue; primaryColor ??= isDark ? Colors.grey[900] : primarySwatch[500]; primaryColorBrightness ??= Brightness.dark; final bool primaryIsDark = primaryColorBrightness == Brightness.dark; accentColor ??= isDark ? Colors.tealAccent[200] : primarySwatch[500]; accentColorBrightness ??= isDark ? Brightness.light : Brightness.dark; final bool accentIsDark = accentColorBrightness == Brightness.dark; canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50]; scaffoldBackgroundColor ??= canvasColor; cardColor ??= isDark ? Colors.grey[800] : Colors.white; dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000); highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor; splashColor ??= isDark ? _kDarkThemeSplashColor : _kLightThemeSplashColor; selectedRowColor ??= Colors.grey[100]; unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54; disabledColor ??= isDark ? Colors.white30 : Colors.black26; buttonColor ??= isDark ? primarySwatch[600] : Colors.grey[300]; // Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess. secondaryHeaderColor ??= isDark ? Colors.grey[700] : primarySwatch[50]; textSelectionColor ??= isDark ? accentColor : primarySwatch[200]; textSelectionHandleColor ??= isDark ? Colors.tealAccent[400] : primarySwatch[300]; backgroundColor ??= isDark ? Colors.grey[700] : primarySwatch[200]; indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor; hintColor ??= isDark ? const Color(0x42FFFFFF) : const Color(0x4C000000); errorColor ??= Colors.red[700]; iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); accentIconTheme ??= accentIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); platform ??= defaultTargetPlatform; final Typography typography = new Typography(platform: platform); textTheme ??= isDark ? typography.white : typography.black; primaryTextTheme ??= primaryIsDark ? typography.white : typography.black; accentTextTheme ??= accentIsDark ? typography.white : typography.black; return new ThemeData.raw( brightness: brightness, primaryColor: primaryColor, primaryColorBrightness: primaryColorBrightness, accentColor: accentColor, accentColorBrightness: accentColorBrightness, canvasColor: canvasColor, scaffoldBackgroundColor: scaffoldBackgroundColor, cardColor: cardColor, dividerColor: dividerColor, highlightColor: highlightColor, splashColor: splashColor, selectedRowColor: selectedRowColor, unselectedWidgetColor: unselectedWidgetColor, disabledColor: disabledColor, buttonColor: buttonColor, secondaryHeaderColor: secondaryHeaderColor, textSelectionColor: textSelectionColor, textSelectionHandleColor: textSelectionHandleColor, backgroundColor: backgroundColor, indicatorColor: indicatorColor, hintColor: hintColor, errorColor: errorColor, textTheme: textTheme, primaryTextTheme: primaryTextTheme, accentTextTheme: accentTextTheme, iconTheme: iconTheme, primaryIconTheme: primaryIconTheme, accentIconTheme: accentIconTheme, platform: platform ); }