Themed class

Instead of:

Container( color: Theme.of(context).warningColor, child: Text("hello!", style: Theme.of(context).titleTextStyle, );

You can write:

Container( color: const AppColor.warning, child: Text("hello!", style: const AppStyle.title, );

Wrap your widget tree with the Themed widget. Note, there must at most one single Themed widget in the tree.

import 'package:themed/themed.dart';

@override
Widget build(BuildContext context) {
  return Themed(
      child: Scaffold( ... )
  );
}

You can provide a default theme theme, like this:

return Themed(
    defaultTheme: { ... },
    child: Scaffold( ... )
Inheritance

Constructors

Themed({Key? key, Map<ThemeRef, Object>? defaultTheme, Map<ThemeRef, Object>? currentTheme, required Widget child})
The Themed widget should wrap the child which contains the tree of widgets you want to use the color theme. It' recommended that you provide a defaultTheme.

Properties

child Widget
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _ThemedState
Creates the mutable state for this widget at a given location in the tree.
override
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 Properties

currentTheme Map<ThemeRef, Object>?
Same as Themed.of(context).currentTheme = { ... };
no getter
defaultTheme Map<ThemeRef, Object>?
Same as Themed.of(context).defaultTheme = { ... };
no getter
transformColor ← (Color Function(Color)?)
Same as Themed.of(context).transformColor = ...;
no getter
transformTextStyle ← (TextStyle Function(TextStyle)?)
Same as Themed.of(context).transformTextStyle = ...;
no getter

Static Methods

clearCurrentTheme() → void
Same as Themed.of(context).clearTheme();
clearSavedThemeByKey([Object? key]) → void
Removes all saved themes. Or, to remove just a specific saved theme, pass its key. Note: This will not change the current theme.
clearTransformColor() → void
Same as Themed.of(context).clearTransformColor();
clearTransformTextStyle() → void
Same as Themed.of(context).clearTransformTextStyle();
ifCurrentThemeIs(Map<ThemeRef, Object> theme) bool
Returns true if the given theme is equal to the current one. Note: To check if the default them is being used, do: ifThemeIs({}).
ifCurrentTransformColorIs(Color transform(Color)?) bool
Same as Themed.ifCurrentTransformColorIs( ... ).
ifCurrentTransformTextStyleIs(TextStyle transform(TextStyle)?) bool
Same as Themed.ifCurrentTransformTextStyleIs( ... ).
of(BuildContext context) → _ThemedState
Getter: print(Themed.of(context).theme);
save({required Object key, required Map<ThemeRef, Object> theme}) → void
Saves a theme with a key. See setThemeByKey to understand how to use the saved theme.
saveAll(Map<dynamic, Map<ThemeRef, Object>> themesByKey) → void
Saves a map of themes by key. Example:
setThemeByKey(Object key) → void
If you call setThemeByKey with a key, and a theme was previously saved with that key (by using the save method), then the current theme will immediately change into that theme.