app_theme_mode 1.0.0 copy "app_theme_mode: ^1.0.0" to clipboard
app_theme_mode: ^1.0.0 copied to clipboard

Widgets to control your app theme mode during runtime and save it how you wishing.

App Theme Mode #

pub License: MIT codecov

Widgets to control your app theme mode during runtime and save it how you wishing.

It's very similar to dynamic_theme_mode_package.

Why? #

There is no business logic here, only widgets that control the theme mode, you choose how you want to save with SharedPreferences, Hive... any one.

Usage #

dependencies:
  app_theme_mode:

Import it where you want to use it e.g, in your main file.

import 'package:app_theme_mode/app_theme_mode.dart';

Put the AppThemeMode widget, above MaterialApp/CupertinoApp or another that had theme mode.

AppThemeMode(
    builder: (context, themeMode) => MaterialApp(        
        title: 'Flutter Demo',
        themeMode: themeMode,
        darkTheme: ThemeData.dark(),
        theme: ThemeData.light(),
        home: const MyHomePage(
          title: 'Flutter Demo Home Page',
        ),
    ),
);

Set the initial theme mode:

AppThemeMode(
    initialThemeMode: ThemeMode.light // System mode is the default
    builder: (context, themeMode)...
);

Get the theme mode saved of your business logic. This is set only one time.

Add a callback for when a new different theme mode is set:

AppThemeMode(
    onChangeThemeMode: (themeMode) {
      // call your business logic to save 
      // the current theme mode here.
    },
    builder: (context, themeMode)...
);

Here you can call your logic business for the save current theme mode.

You can access the current theme mode:

final currentTheme = AppThemeMode.of(context).themeMode;

All the time that a new different theme mode is set the widget is rebuilt.

Or set a new theme mode:

AppThemeMode.of(context).setThemeMode(ThemeMode.dark);
// or
AppThemeMode.of(context).useDarkMode();

There is a dialog widget called AppThemeModeDialog for the user to choose which theme mode he wants

IconButton(
    icon: const Icon(Icons.access_time_sharp),
    onPressed: () => showDialog(
        context: context,
        builder: (_) => const AppThemeModeDialog(),
    ),
),

📝 Maintainers #

Kauê Martins

🤝 Support #

You liked this package? Then give it a ⭐️. If you want to help then:

  • Fork this repository
  • Send a Pull Request with new features
  • Share this package
  • Create issues if you find a bug or want to suggest a new extension

**Pull Request title follows Conventional Commits.

📝 License #

Copyright © 2022 Kauê Martins.
This project is MIT licensed.

1
likes
140
pub points
53%
popularity

Publisher

verified publisherkmartins.dev

Widgets to control your app theme mode during runtime and save it how you wishing.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on app_theme_mode