juice_theme library

App theme selection as a Juice bloc.

ThemeBloc owns the theme selectionThemeMode mode plus an optional named flavor — and persists it through a swappable ThemePersistence seam (default: StorageThemePersistence). It owns the selection, not the ThemeData: feed bloc.state.mode to MaterialApp.themeMode and map bloc.state.flavor to your own themes.

final theme = ThemeBloc.withConfig(
  ThemeConfig(persistence: StorageThemePersistence(storageBloc)),
);

class App extends StatelessJuiceWidget<ThemeBloc> {
  App({super.key}) : super(groups: {ThemeGroups.mode});
  @override
  Widget onBuild(BuildContext context, StreamStatus status) => MaterialApp(
        themeMode: bloc.state.mode,
        theme: lightTheme, darkTheme: darkTheme,
        home: const Home(),
      );
}

Classes

InitializeThemeEvent
Configure persistence and load the saved selection (or defaults).
SetFlavorEvent
Set (or clear, with null) the named flavor.
SetThemeModeEvent
Set the theme mode explicitly.
StorageThemePersistence
Default ThemePersistence backed by StorageBloc (SharedPreferences).
ThemeBloc
Bloc that owns the app's theme selection (mode + optional flavor).
ThemeConfig
Configuration for ThemeBloc.
ThemeEvent
Base class for theme events.
ThemeGroups
Rebuild groups emitted by ThemeBloc.
ThemePersistence
Vendor seam for persisting the theme selection.
ThemeSelection
A persisted theme selection.
ThemeState
Immutable theme-selection state.
ToggleThemeEvent
Flip between light and dark (system → dark).

Enums

ThemeMode
Describes which theme will be used by MaterialApp.