Skip to content

Configure scope and theme mode

Place DievasScope above widgets that consume Dievas.

Pass its resolved Material theme to MaterialApp so Flutter and Dievas controls share the same appearance.

This application follows the platform’s appearance by default:

class ThemedApp extends StatelessWidget {
const ThemedApp({super.key});
@override
Widget build(BuildContext context) => DievasScope(
themeMode: .system,
lightTheme: DievasLightThemeData(),
darkTheme: DievasDarkThemeData(),
builder: (context, theme, child) => MaterialApp(
theme: theme.material,
localizationsDelegates: DievasLocalizations.localizationsDelegates,
supportedLocales: DievasLocalizations.supportedLocales,
home: const Scaffold(body: Center(child: Text('Theme connected'))),
),
);
}

The scope’s builder runs before the returned Dievas ancestor is installed.

Use its theme argument there.

Read context.colours and other extensions below the scope.

Use the scope controller to change mode at runtime:

class DarkModeAction extends StatelessWidget {
const DarkModeAction({super.key});
@override
Widget build(BuildContext context) => DievasTextButton(
label: 'Use dark appearance',
onPressed: () => DievasScope.of(context).setThemeMode(ThemeMode.dark),
);
}

Use ThemeMode.light to force light appearance or ThemeMode.system to follow platform changes.

The scope does not persist preferences across application restarts.

Save the selected mode in your application and restore it through themeMode.

DievasTheme uses an InheritedModel with named theme aspects.

Reading context.spacing subscribes the widget to that aspect.

Prefer reading the subsystem you need instead of depending on the complete theme unnecessarily.

Change all 3 theme modes and confirm both Material surfaces and Dievas components update.

If a context lookup fails, check that the caller is below DievasScope.

Apply a brand palette.