Skip to content

Theme

Shares a ThemeData with its subtree. Read it with Theme.of(context) or the context.theme shorthand (which fall back to ThemeData.fallback when absent, so widgets can always resolve a theme without a required ancestor).

Learn more: Theming

Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.

// Override the theme for one subtree, starting from the one above it:
Theme(
data: Theme.of(context).copyWith(borderStyle: BorderStyle.double),
child: child,
)
// Any descendant reads the nearest theme:
final primary = Theme.of(context).colorScheme.primary;

An app usually sets its theme once, with FleuryApp(theme: ...), which installs a Theme above the whole app. Nest another Theme to restyle one subtree. The inner theme replaces the outer one below it; nothing is merged, so derive it from the enclosing theme to change only some fields.

Wrapping a subtree in a Theme also cascades ThemeData.textStyle as the DefaultTextStyle, so a base text color/dim can be set app-wide in one place.

ParameterTypeDefaultDescription
data:ThemeDatarequiredThe theme for everything below this widget, replacing any theme above it rather than merging with it. More
child:WidgetrequiredThe subtree that reads data.
  • data: Descendants read it with Theme.of, context.theme, or context.colors (its ThemeData.colorScheme), and those readers rebuild when data changes (compared with ==). To override only a few fields, pass the enclosing theme’s Theme.of(context).copyWith(...), read where you build this widget. Its ThemeData.textStyle likewise replaces the subtree’s DefaultTextStyle.

Theme is defined in packages/fleury/lib/src/widgets/theme.dart.

Category: App & theming · All widgets