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.
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
actionIconTheme → ActionIconThemeData?
A theme for customizing icons of BackButtonIcon, CloseButtonIcon,DrawerButtonIcon, or EndDrawerButtonIcon.
final
adaptationMap → Map<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
A theme for customizing the color, elevation, brightness, iconTheme and textTheme of AppBars.
final
applyElevationOverlayColor → bool
Apply a semi-transparent overlay color on Material surfaces to indicate elevation for dark themes.
final
A theme for customizing the color of Badges.
final
A theme for customizing the color and text style of a MaterialBanner.
final
bottomAppBarTheme → BottomAppBarTheme
A theme for customizing the shape, elevation, and color of a BottomAppBar.
final
bottomNavigationBarTheme → BottomNavigationBarThemeData
A theme for customizing the appearance and layout of BottomNavigationBarwidgets.
final
bottomSheetTheme → BottomSheetThemeData
A theme for customizing the color, elevation, and shape of a bottom sheet.
final
The overall theme brightness.
no setter
buttonBarTheme → ButtonBarThemeData
A theme for customizing the appearance and layout of ButtonBar widgets.
no setter
Defines the default configuration of button widgets, like DropdownButtonand ButtonBar.
final
The default color of MaterialType.canvas Material.
final
The color of Material when it is used as a Card.
final
The colors and styles used to render Card.
final
checkboxTheme → CheckboxThemeData
A theme for customizing the appearance and layout of Checkbox widgets.
final
The colors and styles used to render Chips.
final
A set of 45 colors based on theMaterial specthat can be used to configure the color properties of most components.
final
cupertinoOverrideTheme → NoDefaultCupertinoThemeData?
Components of the CupertinoThemeData to override from the MaterialThemeData adaptation.
final
dataTableTheme → DataTableThemeData
A theme for customizing the appearance and layout of DataTablewidgets.
final
datePickerTheme → DatePickerThemeData
A theme for customizing the appearance and layout of DatePickerDialogwidgets.
final
The background color of Dialog elements.
final
A theme for customizing the shape of a dialog.
final
The color used for widgets that are inoperative, regardless of their state. For example, a disabled checkbox (which may be checked or unchecked).
final
The color of Dividers and PopupMenuDividers, also used between ListTiles, between rows in DataTables, and so forth.
final
dividerTheme → DividerThemeData
A theme for customizing the color, thickness, and indents of Dividers,VerticalDividers, etc.
final
A theme for customizing the appearance and layout of Drawer widgets.
final
A theme for customizing the appearance and layout of DropdownMenu widgets.
final
elevatedButtonTheme → ElevatedButtonThemeData
A theme for customizing the appearance and internal layout ofElevatedButtons.
final
expansionTileTheme → ExpansionTileThemeData
A theme for customizing the visual properties of ExpansionTiles.
final
extensions → Map<Object, ThemeExtension>
Arbitrary additions to this theme.
final
filledButtonTheme → FilledButtonThemeData
A theme for customizing the appearance and internal layout ofFilledButtons.
final
floatingActionButtonTheme → FloatingActionButtonThemeData
A theme for customizing the shape, elevation, and color of aFloatingActionButton.
final
The focus color used indicate that a component has the input focus.
final
The hash code for this object.
no setteroverride
The highlight color used during ink splash animations or to indicate an item in a menu is selected.
final
The color to use for hint text or placeholder text, e.g. inTextField fields.
final
The hover color used to indicate when a pointer is hovering over a component.
final
iconButtonTheme → IconButtonThemeData
A theme for customizing the appearance and internal layout ofIconButtons.
final
An icon theme that contrasts with the card and canvas colors.
final
The color of the selected tab indicator in a tab bar.
final
inputDecorationTheme → InputDecorationTheme
The default InputDecoration values for InputDecorator, TextField, and TextFormField are based on this theme.
final
listTileTheme → ListTileThemeData
A theme for customizing the appearance of ListTile widgets.
final
materialTapTargetSize → MaterialTapTargetSize
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
navigationBarTheme → NavigationBarThemeData
A theme for customizing the background color, text style, and icon themes of a NavigationBar.
final
navigationDrawerTheme → NavigationDrawerThemeData
A theme for customizing the background color, text style, and icon themes of a NavigationDrawer.
final
navigationRailTheme → NavigationRailThemeData
A theme for customizing the background color, elevation, text style, and icon themes of a NavigationRail.
final
outlinedButtonTheme → OutlinedButtonThemeData
A theme for customizing the appearance and internal layout ofOutlinedButtons.
final
pageTransitionsTheme → PageTransitionsTheme
Default MaterialPageRoute transitions per TargetPlatform.
final
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
The background color for major parts of the app (toolbars, tab bars, etc)
final
A darker version of the primaryColor.
final
A lighter version of the primaryColor.
final
primaryIconTheme → IconThemeData
An icon theme that contrasts with the primary color.
final
A text theme that contrasts with the primary color.
final
progressIndicatorTheme → ProgressIndicatorThemeData
A theme for customizing the appearance and layout of ProgressIndicator widgets.
final
A theme for customizing the appearance and layout of Radio widgets.
final
A representation of the runtime type of the object.
no setterinherited
scaffoldBackgroundColor → Color
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
scrollbarTheme → ScrollbarThemeData
A theme for customizing the colors, thickness, and shape of Scrollbars.
final
searchBarTheme → SearchBarThemeData
A theme for customizing the appearance and layout of SearchBar widgets.
final
searchViewTheme → SearchViewThemeData
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
segmentedButtonTheme → SegmentedButtonThemeData
A theme for customizing the appearance and layout of SegmentedButton widgets.
final
The color that the Material widget uses to draw elevation shadows.
final
The colors and shapes used to render Slider.
final
snackBarTheme → SnackBarThemeData
A theme for customizing colors, shape, elevation, and behavior of a SnackBar.
final
The color of ink splashes.
final
splashFactory → InteractiveInkFeatureFactory
Defines the appearance of ink splashes produces by InkWelland InkResponse.
final
A theme for customizing the appearance and layout of Switch widgets.
final
A theme for customizing the size, shape, and color of the tab bar indicator.
final
textButtonTheme → TextButtonThemeData
A theme for customizing the appearance and internal layout ofTextButtons.
final
textSelectionTheme → TextSelectionThemeData
A theme for customizing the appearance and layout of TextField widgets.
final
Text with a color that contrasts with the card and canvas colors.
final
timePickerTheme → TimePickerThemeData
A theme for customizing the appearance and layout of time picker widgets.
final
toggleButtonsTheme → ToggleButtonsThemeData
Defines the default configuration of ToggleButtons widgets.
final
tooltipTheme → TooltipThemeData
A theme for customizing the visual properties of Tooltips.
final
The color and geometry TextTheme values used to configure textTheme.
final
The color used for widgets in their inactive (but enabled) state. For example, an unchecked checkbox. See also disabledColor.
final
A temporary flag that can be used to opt-out of Material 3 features.
final
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
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
.