theme_genius 2.0.0 copy "theme_genius: ^2.0.0" to clipboard
theme_genius: ^2.0.0 copied to clipboard

A Flutter package that provides a simple way to manage theme modes in your app.

ThemeGenius #

version coverage style: very good analysis Powered by Mason License: MIT

A Flutter package that provides a simple way to manage theme modes in your app.


Migration from 1.x to 2.x 🚀 #

In the new version 2.x, we migrated from the legacy SharedPreferences API to the new SharedPreferencesAsync API. This change allows you to avoid using an API that will be deprecated in the future. See this link for more information.

Installation 💻 #

❗ In order to start using ThemeGenius you must have the Flutter SDK installed on your machine.

  • Install via flutter pub add:
dart pub add theme_genius
copied to clipboard
  • Or add this to your pubspec.yaml:
dependencies:
  theme_genius: ^2.0.0
copied to clipboard

Usage 📖 #

  • Import the ThemeGeniusWrapper widget, wrap MaterialApp with it:
import 'package:theme_genius/theme_genius.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ThemeGeniusWrapper(
      builder: (themeMode) {
        return MaterialApp(
          themeMode: themeMode,
          theme: ThemeData.light(),
          darkTheme: ThemeData.dark(),
          home: const MyHomePage(
            title: 'Flutter Demo Home Page',
          ),
        );
      },
    );
  }
}
copied to clipboard
  • Get the current themeMode with:
final themeMode = await ThemeGenius.getThemeMode(context);

copied to clipboard
  • Change and save the themeMode with:
final themeMode = ThemeMode.dark;
await ThemeGenius.setThemeMode(context, themeMode: themeMode);

copied to clipboard
  • Load the saved themeMode with:
final themeMode = await ThemeGenius.loadThemeMode();

copied to clipboard

Check the example folder for a complete example.


Extra 📖 #

  • Set the defaultThemeMode in ThemeGeniusWrapper with:
@override
Widget build(BuildContext context) {
  return ThemeGeniusWrapper(
    builder: (themeMode) {
      return MaterialApp(...);
    },
    defaultThemeMode: ThemeMode.dark,
  );
}
copied to clipboard
  • Set a custom placeholder (a widget to display while the theme mode is being loaded) in ThemeGeniusWrapper with:
@override
Widget build(BuildContext context) {
  return ThemeGeniusWrapper(
    builder: (themeMode) {
      return MaterialApp(...);
    },
    placeholder: const Scaffold(
      body: Center(
        child: CircularProgressIndicator(),
      ),
    ),
  );
}
copied to clipboard

Continuous Integration 🤖 #

Theme Genius comes with a built-in GitHub Actions workflow powered by Very Good Workflows but you can also add your preferred CI/CD solution.

Out of the box, on each pull request and push, the CI formats, lints, and tests the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses Very Good Analysis for a strict set of analysis options used by our team. Code coverage is enforced using the Very Good Workflows.

License 📄 #

MIT © 2012-2023 Scott Chacon and others

2
likes
160
points
54
downloads

Publisher

verified publishertizianotedeschi.com

Weekly Downloads

2024.08.27 - 2025.03.11

A Flutter package that provides a simple way to manage theme modes in your app.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on theme_genius