NakiThemeProvider class

A Naki component that propagates theme state down the component tree.

  • Enables switching between theme modes.
  • Caches theme mode and restores it in subsequent sessions.
  • Can be used as the root component of a Jaspr application or wrap a Naki component to access and use theme-specific styles.

For a more robust theme management, consider using NakiApp or NakiThemeProvider.fromConfig constructor in a @client annotated component.

Example

@override
Component build(BuildContext context) {
  return NakiThemeProvider(
    mode: ThemeMode.light,
    builder: (context) => const Scaffold(
      body: NakiText('Hello world'),
    ),
  );
}

Constructors

NakiThemeProvider({required ComponentBuilder builder, ThemeMode mode = ThemeMode.system, ValueChanged<ThemeMode>? onModeChanged, Key? key})
A Naki component that propagates theme state down the component tree.
const
NakiThemeProvider.fromConfig({required ThemeConfig? configuration, required ComponentBuilder builder, Key? key})
Creates a NakiThemeProvider instance using ThemeConfig.

Properties

builder → ComponentBuilder
Child component subtree.
final
configuration → ThemeConfig?
ThemeConfig enables you to customize theme by:
final
enableCache → bool
Allow theme mode caching and restoration on page loads.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one component replaces another component in the tree.
finalinherited
mode → ThemeMode
Initial theme mode (default is ThemeMode.system).
final
onModeChanged → ValueChanged<ThemeMode>?
Optional callback executed when theme mode changes.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → Element
Creates a StatefulElement to manage this component's location in the tree.
inherited
createState() → State<NakiThemeProvider>
Creates the mutable state for this component at a given location in the tree.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

styles → List<StyleRule>
no setter

Static Methods

brightnessOf(BuildContext context) → Brightness
Brightness of the active theme relative to the context.
of(BuildContext context) → InheritedTheme?
Finds the nearest InheritedTheme instance in the component tree. This scans the component tree upwards from the parent of context until it finds an instance of InheritedTheme.
setMode(BuildContext context, ThemeMode mode) → bool
Sets theme mode to the provided mode.
systemBrightness(BuildContext context) → Brightness?
System brightness is only available in client-side.
toggleMode(BuildContext context) → bool
Toggles the current theme mode.
tokensOf(BuildContext context) → Tokens
Design tokens of the active theme relative to the context.