Themed class Null safety

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';

Widget build(BuildContext context) {
  return Themed(
      child: Scaffold( ... )

You can provide a default theme theme, like this:

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


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.


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


createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
createState() → _ThemedState
Creates the mutable state for this widget at a given location in the tree.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator.

Static Properties

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

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.