ThemeProvider class
Wrap MaterialApp in ThemeProvider to get theme functionalities. You may wrap separate parts of the app with multiple ThemeProviders to use multiple theme sections across the app.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- ThemeProvider
Constructors
-
ThemeProvider({Key? key, String providerId = "default", List<
AppTheme> ? themes, String? defaultThemeId, ThemeControllerHandler? onInitCallback, ThemeChanged? onThemeChanged, required Widget child, bool saveThemesOnChange = false, bool loadThemeOnInit = false}) - Creates a ThemeProvider. Wrap MaterialApp in ThemeProvider to get theme functionalities. You may wrap separate parts of the app with multiple ThemeProviders to use multiple theme sections across the app.
Properties
- child → Widget
-
The widget below this widget in the tree.
final
- defaultThemeId → String?
-
Optional field which will set the default theme out of themes provided in themes.
If not provided, default theme will be the first provided theme.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loadThemeOnInit → bool
-
Whether to load the theme on initialization.
If
true
, default onInitCallback will be executed instead.final - onInitCallback → ThemeControllerHandler?
-
The callback which is to be called when the ThemeController is first initialed.
final
- onThemeChanged → ThemeChanged?
-
The callback which is to be called when the AppTheme is changed.
final
- providerId → String
-
Theme provider id to distinguish between ThemeProviders.
Provide distinct values if you intend to use multiple theme providers.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- saveThemesOnChange → bool
-
Whether to persist the theme on change.
If
true
, theme will be saved to disk whenever the theme changes. By default this isfalse
.final -
themes
→ List<
AppTheme> -
List of themes to be available for child listeners.
If themes are not supplies AppTheme.light() and AppTheme.dark() is assumed.
If themes are supplied, there have to be at least 2
AppTheme
objects inside the list.final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
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
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
controllerOf(
BuildContext context) → ThemeController -
Gives reference to a
ThemeCommand
of the nearest ThemeProvider up the widget tree and will provide commands to change the theme. -
optionsOf<
T extends AppThemeOptions> (BuildContext context) → T -
Returns the options passed by the nearest ThemeProvider up the widget tree.
Call as
ThemeProvider.optionsOf<ColorClass>(context)
to get the returned object casted to the required type. -
themeOf(
BuildContext context) → AppTheme -
Returns the current app theme passed by the nearest ThemeProvider up the widget tree.
Use as
ThemeProvider.themeOf(context).data
to get ThemeData.