theme_manager 2.0.4 copy "theme_manager: ^2.0.4" to clipboard
theme_manager: ^2.0.4 copied to clipboard

A theme manager for light, dark, and system themes. Change the theme dynamically and the selected theme will be persisted.

theme_manager #

A theme manager for light, dark, and system themes. #

A theme manager that supports light, dark, and system default themes. State is retained and applied upon application start. Heavily inspired by dynamic_theme by Norbert Kozsir.

Getting Started #

Add theme_manager to your project.

  dependencies:
    theme_manager: ^2.0.4
copied to clipboard

run flutter packages get and import theme_manager

import 'package:theme_manager/theme_manager.dart';
copied to clipboard

A dialog is provided that can switch between themes.

import 'package:theme_manager/theme_picker_dialog.dart';
copied to clipboard

How to use #

Make sure WidgetsFlutterBinding are initialized. This is required.

void main() {
  WidgetsFlutterBinding.ensureInitialized(); // Required
  runApp(MyApp());
}
copied to clipboard

Wrap your MaterialApp with ThemeManager:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ThemeManager(
      defaultBrightnessPreference: BrightnessPreference.system,
      data: (Brightness brightness) => ThemeData(
        primarySwatch: Colors.blue,
        accentColor: Colors.lightBlue,
        brightness: brightness,
      ),
      loadBrightnessOnStart: true,
      themedWidgetBuilder: (BuildContext context, ThemeData theme) {
        return MaterialApp(
          title: 'Theme Manager Demo',
          theme: theme,
          home: MyHomePage(),
        );
      },
    );
  }
}
copied to clipboard

When you want to change your theme:

void setAsSystemDefault() => 
  ThemeManager.of(context).setBrightnessPreference(BrightnessPreference.system);
void setAsLight() => 
  ThemeManager.of(context).setBrightnessPreference(BrightnessPreference.light);
void setAsDark() => 
  ThemeManager.of(context).setBrightnessPreference(BrightnessPreference.dark);
copied to clipboard

The system default will load either light or dark based on the device preferences. If your device changes themes at sunset or sunrise then light/dark mode will apply automatically.

The BrightnessPreference is saved in SharedPreferences automatically. There is also a clear function to remove the preferences.

void clear() => ThemeManager.of(context).clearBrightnessPreference();
copied to clipboard

A dialog widget to change the brightness! #

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

34
likes
160
points
637
downloads

Publisher

unverified uploader

Weekly Downloads

2024.07.08 - 2025.01.20

A theme manager for light, dark, and system themes. Change the theme dynamically and the selected theme will be persisted.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

equatable, flutter, platform, shared_preferences

More

Packages that depend on theme_manager