ThemeData class - material library (original) (raw)

Defines the configuration of the overall visual Theme for a MaterialAppor a widget subtree within the app.

The MaterialApp theme property can be used to configure the appearance of the entire app. Widget subtrees within an app can override the app's theme by including a Theme widget at the top of the subtree.

Widgets whose appearance should align with the overall theme can obtain the current theme's configuration with Theme.of. Material components typically depend exclusively on the colorScheme and textTheme. These properties are guaranteed to have non-null values.

The static Theme.of method finds the ThemeData value specified for the nearest BuildContext ancestor. This lookup is inexpensive, essentially just a single HashMap access. It can sometimes be a little confusing because Theme.of can not see a Theme widget that is defined in the current build method's context. To overcome that, create a new custom widget for the subtree that appears below the new Theme, or insert a widget that creates a new BuildContext, like Builder.

This example demonstrates how a typical MaterialApp specifies and uses a custom Theme. The theme's ColorScheme is based on a single "seed" color and configures itself to match the platform's current light or dark color configuration. The theme overrides the default configuration of FloatingActionButton to show how to customize the appearance a class of components.

link

To create a local project with this code sample, run:
flutter create --sample=material.ThemeData.1 mysample

See material.io/design/color/ for more discussion on how to pick the right colors.

Mixed-in types

Annotations

Constructors

ThemeData({Iterable<Adaptation<Object>>? adaptations, bool? applyElevationOverlayColor, NoDefaultCupertinoThemeData? cupertinoOverrideTheme, Iterable<ThemeExtension>? extensions, InputDecorationTheme? inputDecorationTheme, MaterialTapTargetSize? materialTapTargetSize, PageTransitionsTheme? pageTransitionsTheme, TargetPlatform? platform, ScrollbarThemeData? scrollbarTheme, InteractiveInkFeatureFactory? splashFactory, bool? useMaterial3, VisualDensity? visualDensity, ColorScheme? colorScheme, Brightness? brightness, Color? colorSchemeSeed, Color? canvasColor, Color? cardColor, Color? disabledColor, Color? dividerColor, Color? focusColor, Color? highlightColor, Color? hintColor, Color? hoverColor, Color? indicatorColor, Color? primaryColor, Color? primaryColorDark, Color? primaryColorLight, MaterialColor? primarySwatch, Color? scaffoldBackgroundColor, Color? shadowColor, Color? splashColor, Color? unselectedWidgetColor, String? fontFamily, List<String>? fontFamilyFallback, String? package, IconThemeData? iconTheme, IconThemeData? primaryIconTheme, TextTheme? primaryTextTheme, TextTheme? textTheme, Typography? typography, ActionIconThemeData? actionIconTheme, AppBarTheme? appBarTheme, BadgeThemeData? badgeTheme, BottomAppBarTheme? bottomAppBarTheme, BottomNavigationBarThemeData? bottomNavigationBarTheme, BottomSheetThemeData? bottomSheetTheme, ButtonThemeData? buttonTheme, Object? cardTheme, CheckboxThemeData? checkboxTheme, ChipThemeData? chipTheme, DataTableThemeData? dataTableTheme, DatePickerThemeData? datePickerTheme, Object? dialogTheme, DividerThemeData? dividerTheme, DrawerThemeData? drawerTheme, ElevatedButtonThemeData? elevatedButtonTheme, ExpansionTileThemeData? expansionTileTheme, FilledButtonThemeData? filledButtonTheme, FloatingActionButtonThemeData? floatingActionButtonTheme, IconButtonThemeData? iconButtonTheme, ListTileThemeData? listTileTheme, NavigationBarThemeData? navigationBarTheme, NavigationDrawerThemeData? navigationDrawerTheme, NavigationRailThemeData? navigationRailTheme, OutlinedButtonThemeData? outlinedButtonTheme, ProgressIndicatorThemeData? progressIndicatorTheme, RadioThemeData? radioTheme, SearchBarThemeData? searchBarTheme, SearchViewThemeData? searchViewTheme, SegmentedButtonThemeData? segmentedButtonTheme, SliderThemeData? sliderTheme, SnackBarThemeData? snackBarTheme, SwitchThemeData? switchTheme, Object? tabBarTheme, TextButtonThemeData? textButtonTheme, TextSelectionThemeData? textSelectionTheme, TimePickerThemeData? timePickerTheme, ToggleButtonsThemeData? toggleButtonsTheme, TooltipThemeData? tooltipTheme, @Deprecated('Use OverflowBar instead. ' 'This feature was deprecated after v3.21.0-10.0.pre.') ButtonBarThemeData? buttonBarTheme, @Deprecated('Use DialogThemeData.backgroundColor instead. ' 'This feature was deprecated after v3.27.0-0.1.pre.') Color? dialogBackgroundColor})

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

factory

ThemeData.dark({bool? useMaterial3})

A default dark theme.

factory

ThemeData.fallback({bool? useMaterial3})

The default color theme. Same as ThemeData.light.

factory

ThemeData.from({required ColorScheme colorScheme, TextTheme? textTheme, bool? useMaterial3})

Create a ThemeData based on the colors in the given colorScheme and text styles of the optional textTheme.

factory

ThemeData.light({bool? useMaterial3})

A default light theme.

factory

ThemeData.raw({required Map<Type, Adaptation<Object>> adaptationMap, required bool applyElevationOverlayColor, required NoDefaultCupertinoThemeData? cupertinoOverrideTheme, required Map<Object, ThemeExtension> extensions, required InputDecorationTheme inputDecorationTheme, required MaterialTapTargetSize materialTapTargetSize, required PageTransitionsTheme pageTransitionsTheme, required TargetPlatform platform, required ScrollbarThemeData scrollbarTheme, required InteractiveInkFeatureFactory splashFactory, required bool useMaterial3, required VisualDensity visualDensity, required ColorScheme colorScheme, required Color canvasColor, required Color cardColor, required Color disabledColor, required Color dividerColor, required Color focusColor, required Color highlightColor, required Color hintColor, required Color hoverColor, required Color indicatorColor, required Color primaryColor, required Color primaryColorDark, required Color primaryColorLight, required Color scaffoldBackgroundColor, required Color shadowColor, required Color splashColor, required Color unselectedWidgetColor, required IconThemeData iconTheme, required IconThemeData primaryIconTheme, required TextTheme primaryTextTheme, required TextTheme textTheme, required Typography typography, required ActionIconThemeData? actionIconTheme, required AppBarTheme appBarTheme, required BadgeThemeData badgeTheme, required BottomAppBarTheme bottomAppBarTheme, required BottomNavigationBarThemeData bottomNavigationBarTheme, required BottomSheetThemeData bottomSheetTheme, required ButtonThemeData buttonTheme, required CardThemeData cardTheme, required CheckboxThemeData checkboxTheme, required ChipThemeData chipTheme, required DataTableThemeData dataTableTheme, required DatePickerThemeData datePickerTheme, required DialogThemeData dialogTheme, required DividerThemeData dividerTheme, required DrawerThemeData drawerTheme, required ElevatedButtonThemeData elevatedButtonTheme, required ExpansionTileThemeData expansionTileTheme, required FilledButtonThemeData filledButtonTheme, required FloatingActionButtonThemeData floatingActionButtonTheme, required IconButtonThemeData iconButtonTheme, required ListTileThemeData listTileTheme, required NavigationBarThemeData navigationBarTheme, required NavigationDrawerThemeData navigationDrawerTheme, required NavigationRailThemeData navigationRailTheme, required OutlinedButtonThemeData outlinedButtonTheme, required ProgressIndicatorThemeData progressIndicatorTheme, required RadioThemeData radioTheme, required SearchBarThemeData searchBarTheme, required SearchViewThemeData searchViewTheme, required SegmentedButtonThemeData segmentedButtonTheme, required SliderThemeData sliderTheme, required SnackBarThemeData snackBarTheme, required SwitchThemeData switchTheme, required TabBarThemeData tabBarTheme, required TextButtonThemeData textButtonTheme, required TextSelectionThemeData textSelectionTheme, required TimePickerThemeData timePickerTheme, required ToggleButtonsThemeData toggleButtonsTheme, required TooltipThemeData tooltipTheme, @Deprecated('Use OverflowBar instead. ' 'This feature was deprecated after v3.21.0-10.0.pre.') ButtonBarThemeData? buttonBarTheme, @Deprecated('Use DialogThemeData.backgroundColor instead. ' 'This feature was deprecated after v3.27.0-0.1.pre.') required Color dialogBackgroundColor})

Create a ThemeData given a set of exact values. Most values must be specified. They all must also be non-null except forcupertinoOverrideTheme, and deprecated members.

const

Properties

actionIconThemeActionIconThemeData?

A theme for customizing icons of BackButtonIcon, CloseButtonIcon,DrawerButtonIcon, or EndDrawerButtonIcon.

final

adaptationMapMap<Type, Adaptation<Object>>

A map which contains the adaptations for the theme. The entry's key is the type of the adaptation; the value is the adaptation itself.

final

appBarThemeAppBarTheme

A theme for customizing the color, elevation, brightness, iconTheme and textTheme of AppBars.

final

applyElevationOverlayColorbool

Apply a semi-transparent overlay color on Material surfaces to indicate elevation for dark themes.

final

badgeThemeBadgeThemeData

A theme for customizing the color of Badges.

final

A theme for customizing the color and text style of a MaterialBanner.

final

bottomAppBarThemeBottomAppBarTheme

A theme for customizing the shape, elevation, and color of a BottomAppBar.

final

bottomNavigationBarThemeBottomNavigationBarThemeData

A theme for customizing the appearance and layout of BottomNavigationBarwidgets.

final

bottomSheetThemeBottomSheetThemeData

A theme for customizing the color, elevation, and shape of a bottom sheet.

final

brightnessBrightness

The overall theme brightness.

no setter

buttonBarThemeButtonBarThemeData

A theme for customizing the appearance and layout of ButtonBar widgets.

no setter

buttonThemeButtonThemeData

Defines the default configuration of button widgets, like DropdownButtonand ButtonBar.

final

canvasColorColor

The default color of MaterialType.canvas Material.

final

cardColorColor

The color of Material when it is used as a Card.

final

cardThemeCardThemeData

The colors and styles used to render Card.

final

checkboxThemeCheckboxThemeData

A theme for customizing the appearance and layout of Checkbox widgets.

final

chipThemeChipThemeData

The colors and styles used to render Chips.

final

colorSchemeColorScheme

A set of 45 colors based on theMaterial specthat can be used to configure the color properties of most components.

final

cupertinoOverrideThemeNoDefaultCupertinoThemeData?

Components of the CupertinoThemeData to override from the MaterialThemeData adaptation.

final

dataTableThemeDataTableThemeData

A theme for customizing the appearance and layout of DataTablewidgets.

final

datePickerThemeDatePickerThemeData

A theme for customizing the appearance and layout of DatePickerDialogwidgets.

final

dialogBackgroundColorColor

The background color of Dialog elements.

final

dialogThemeDialogThemeData

A theme for customizing the shape of a dialog.

final

disabledColorColor

The color used for widgets that are inoperative, regardless of their state. For example, a disabled checkbox (which may be checked or unchecked).

final

dividerColorColor

The color of Dividers and PopupMenuDividers, also used between ListTiles, between rows in DataTables, and so forth.

final

dividerThemeDividerThemeData

A theme for customizing the color, thickness, and indents of Dividers,VerticalDividers, etc.

final

drawerThemeDrawerThemeData

A theme for customizing the appearance and layout of Drawer widgets.

final

A theme for customizing the appearance and layout of DropdownMenu widgets.

final

elevatedButtonThemeElevatedButtonThemeData

A theme for customizing the appearance and internal layout ofElevatedButtons.

final

expansionTileThemeExpansionTileThemeData

A theme for customizing the visual properties of ExpansionTiles.

final

extensionsMap<Object, ThemeExtension>

Arbitrary additions to this theme.

final

filledButtonThemeFilledButtonThemeData

A theme for customizing the appearance and internal layout ofFilledButtons.

final

floatingActionButtonThemeFloatingActionButtonThemeData

A theme for customizing the shape, elevation, and color of aFloatingActionButton.

final

focusColorColor

The focus color used indicate that a component has the input focus.

final

hashCodeint

The hash code for this object.

no setteroverride

highlightColorColor

The highlight color used during ink splash animations or to indicate an item in a menu is selected.

final

hintColorColor

The color to use for hint text or placeholder text, e.g. inTextField fields.

final

hoverColorColor

The hover color used to indicate when a pointer is hovering over a component.

final

iconButtonThemeIconButtonThemeData

A theme for customizing the appearance and internal layout ofIconButtons.

final

iconThemeIconThemeData

An icon theme that contrasts with the card and canvas colors.

final

indicatorColorColor

The color of the selected tab indicator in a tab bar.

final

inputDecorationThemeInputDecorationTheme

The default InputDecoration values for InputDecorator, TextField, and TextFormField are based on this theme.

final

listTileThemeListTileThemeData

A theme for customizing the appearance of ListTile widgets.

final

materialTapTargetSizeMaterialTapTargetSize

Configures the hit test size of certain Material widgets.

final

A theme for customizing the color, shape, elevation, and other MenuStyleaspects of the menu bar created by the MenuBar widget.

final

A theme for customizing the color, shape, elevation, and text style of cascading menu buttons created by SubmenuButton or MenuItemButton.

final

A theme for customizing the color, shape, elevation, and other MenuStyleattributes of menus created by the SubmenuButton widget.

final

navigationBarThemeNavigationBarThemeData

A theme for customizing the background color, text style, and icon themes of a NavigationBar.

final

navigationDrawerThemeNavigationDrawerThemeData

A theme for customizing the background color, text style, and icon themes of a NavigationDrawer.

final

navigationRailThemeNavigationRailThemeData

A theme for customizing the background color, elevation, text style, and icon themes of a NavigationRail.

final

outlinedButtonThemeOutlinedButtonThemeData

A theme for customizing the appearance and internal layout ofOutlinedButtons.

final

pageTransitionsThemePageTransitionsTheme

Default MaterialPageRoute transitions per TargetPlatform.

final

platformTargetPlatform

The platform the material widgets should adapt to target.

final

A theme for customizing the color, shape, elevation, and text style of popup menus.

final

primaryColorColor

The background color for major parts of the app (toolbars, tab bars, etc)

final

primaryColorDarkColor

A darker version of the primaryColor.

final

primaryColorLightColor

A lighter version of the primaryColor.

final

primaryIconThemeIconThemeData

An icon theme that contrasts with the primary color.

final

primaryTextThemeTextTheme

A text theme that contrasts with the primary color.

final

progressIndicatorThemeProgressIndicatorThemeData

A theme for customizing the appearance and layout of ProgressIndicator widgets.

final

radioThemeRadioThemeData

A theme for customizing the appearance and layout of Radio widgets.

final

runtimeTypeType

A representation of the runtime type of the object.

no setterinherited

scaffoldBackgroundColorColor

The default color of the Material that underlies the Scaffold. The background color for a typical material app or a page within the app.

final

scrollbarThemeScrollbarThemeData

A theme for customizing the colors, thickness, and shape of Scrollbars.

final

searchBarThemeSearchBarThemeData

A theme for customizing the appearance and layout of SearchBar widgets.

final

searchViewThemeSearchViewThemeData

A theme for customizing the appearance and layout of search views created by SearchAnchor widgets.

final

The color of the header of a PaginatedDataTable when there are selected rows.

final

segmentedButtonThemeSegmentedButtonThemeData

A theme for customizing the appearance and layout of SegmentedButton widgets.

final

shadowColorColor

The color that the Material widget uses to draw elevation shadows.

final

sliderThemeSliderThemeData

The colors and shapes used to render Slider.

final

snackBarThemeSnackBarThemeData

A theme for customizing colors, shape, elevation, and behavior of a SnackBar.

final

splashColorColor

The color of ink splashes.

final

splashFactoryInteractiveInkFeatureFactory

Defines the appearance of ink splashes produces by InkWelland InkResponse.

final

switchThemeSwitchThemeData

A theme for customizing the appearance and layout of Switch widgets.

final

tabBarThemeTabBarThemeData

A theme for customizing the size, shape, and color of the tab bar indicator.

final

textButtonThemeTextButtonThemeData

A theme for customizing the appearance and internal layout ofTextButtons.

final

textSelectionThemeTextSelectionThemeData

A theme for customizing the appearance and layout of TextField widgets.

final

textThemeTextTheme

Text with a color that contrasts with the card and canvas colors.

final

timePickerThemeTimePickerThemeData

A theme for customizing the appearance and layout of time picker widgets.

final

toggleButtonsThemeToggleButtonsThemeData

Defines the default configuration of ToggleButtons widgets.

final

tooltipThemeTooltipThemeData

A theme for customizing the visual properties of Tooltips.

final

typographyTypography

The color and geometry TextTheme values used to configure textTheme.

final

unselectedWidgetColorColor

The color used for widgets in their inactive (but enabled) state. For example, an unchecked checkbox. See also disabledColor.

final

useMaterial3bool

A temporary flag that can be used to opt-out of Material 3 features.

final

visualDensityVisualDensity

The density value for specifying the compactness of various UI components.

final

Methods

copyWith({Iterable<Adaptation<Object>>? adaptations, bool? applyElevationOverlayColor, NoDefaultCupertinoThemeData? cupertinoOverrideTheme, Iterable<ThemeExtension>? extensions, InputDecorationTheme? inputDecorationTheme, MaterialTapTargetSize? materialTapTargetSize, PageTransitionsTheme? pageTransitionsTheme, TargetPlatform? platform, ScrollbarThemeData? scrollbarTheme, InteractiveInkFeatureFactory? splashFactory, VisualDensity? visualDensity, ColorScheme? colorScheme, Brightness? brightness, Color? canvasColor, Color? cardColor, Color? disabledColor, Color? dividerColor, Color? focusColor, Color? highlightColor, Color? hintColor, Color? hoverColor, Color? indicatorColor, Color? primaryColor, Color? primaryColorDark, Color? primaryColorLight, Color? scaffoldBackgroundColor, Color? shadowColor, Color? splashColor, Color? unselectedWidgetColor, IconThemeData? iconTheme, IconThemeData? primaryIconTheme, TextTheme? primaryTextTheme, TextTheme? textTheme, Typography? typography, ActionIconThemeData? actionIconTheme, AppBarTheme? appBarTheme, BadgeThemeData? badgeTheme, BottomAppBarTheme? bottomAppBarTheme, BottomNavigationBarThemeData? bottomNavigationBarTheme, BottomSheetThemeData? bottomSheetTheme, ButtonThemeData? buttonTheme, Object? cardTheme, CheckboxThemeData? checkboxTheme, ChipThemeData? chipTheme, DataTableThemeData? dataTableTheme, DatePickerThemeData? datePickerTheme, Object? dialogTheme, DividerThemeData? dividerTheme, DrawerThemeData? drawerTheme, ElevatedButtonThemeData? elevatedButtonTheme, ExpansionTileThemeData? expansionTileTheme, FilledButtonThemeData? filledButtonTheme, FloatingActionButtonThemeData? floatingActionButtonTheme, IconButtonThemeData? iconButtonTheme, ListTileThemeData? listTileTheme, NavigationBarThemeData? navigationBarTheme, NavigationDrawerThemeData? navigationDrawerTheme, NavigationRailThemeData? navigationRailTheme, OutlinedButtonThemeData? outlinedButtonTheme, ProgressIndicatorThemeData? progressIndicatorTheme, RadioThemeData? radioTheme, SearchBarThemeData? searchBarTheme, SearchViewThemeData? searchViewTheme, SegmentedButtonThemeData? segmentedButtonTheme, SliderThemeData? sliderTheme, SnackBarThemeData? snackBarTheme, SwitchThemeData? switchTheme, Object? tabBarTheme, TextButtonThemeData? textButtonTheme, TextSelectionThemeData? textSelectionTheme, TimePickerThemeData? timePickerTheme, ToggleButtonsThemeData? toggleButtonsTheme, TooltipThemeData? tooltipTheme, bool? useMaterial3, ButtonBarThemeData? buttonBarTheme, Color? dialogBackgroundColor})→ ThemeData

Creates a copy of this theme but with the given fields replaced with the new values.

debugFillProperties(DiagnosticPropertiesBuilder properties)→ void

Add additional properties associated with the node.

override

extension<T>()→ T?

Used to obtain a particular ThemeExtension from extensions.

getAdaptation<T>()→ Adaptation<T>?

Used to obtain a particular Adaptation from adaptationMap.

noSuchMethod(Invocation invocation)→ dynamic

Invoked when a nonexistent method or property is accessed.

inherited

toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style})→ DiagnosticsNode

Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.

inherited

toString({DiagnosticLevel minLevel = DiagnosticLevel.info})→ String

A string representation of this object.

inherited

toStringShort()→ String

A brief description of this object, usually just the runtimeType and thehashCode.

inherited

Operators

operator ==(Object other)→ bool

The equality operator.

override

Static Methods

estimateBrightnessForColor(Color color)→ Brightness

Determines whether the given Color is Brightness.light orBrightness.dark.

lerp(ThemeData a, ThemeData b, double t)→ ThemeData

Linearly interpolate between two themes.

localize(ThemeData baseTheme, TextTheme localTextGeometry)→ ThemeData

Returns a new theme built by merging the text geometry provided by thelocalTextGeometry theme with the baseTheme.