All Projects → arthurdenner → theme_mode_handler

arthurdenner / theme_mode_handler

Licence: MIT License
Flutter widget to change `themeMode` during runtime and persist it across restarts.

Programming Languages

dart
5743 projects
ruby
36898 projects - #4 most used programming language
kotlin
9241 projects
swift
15916 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to theme mode handler

Web Vuw
A Web View for flutter
Stars: ✭ 40 (+42.86%)
Mutual labels:  flutter-plugin
reactive state
An easy to understand reactive state management solution for Flutter.
Stars: ✭ 19 (-32.14%)
Mutual labels:  flutter-plugin
oscilloscope
A Flutter package that can display an Oscilloscope type graphical display
Stars: ✭ 17 (-39.29%)
Mutual labels:  flutter-plugin
simple beacons flutter
A flutter plugin project to range & monitor iBeacons.
Stars: ✭ 29 (+3.57%)
Mutual labels:  flutter-plugin
flutter nearby connections
Flutter plugin support peer-to-peer connectivity and the discovery of nearby devices for Android vs IOS
Stars: ✭ 51 (+82.14%)
Mutual labels:  flutter-plugin
lang table
lang_table is a dart plugin to generate string files from a source. Use a table to manage all multi-language resources. Inspired by fetch-mobile-localization-from-airtable
Stars: ✭ 17 (-39.29%)
Mutual labels:  flutter-plugin
flutter-moum
Flutter를 좋아하는 사람들이 모여서 Flutter 관련 지식과 기술을 모음📚
Stars: ✭ 67 (+139.29%)
Mutual labels:  flutter-plugin
flutter-tunein
Dynamically themed Music Player built with flutter
Stars: ✭ 108 (+285.71%)
Mutual labels:  flutter-plugin
nepali date picker
Material Style Date Picker with Bikram Sambat(Nepali) Calendar Support. Supports both Android and ios.
Stars: ✭ 30 (+7.14%)
Mutual labels:  flutter-plugin
flutter launch whatsapp
Plugin flutter to launch whatsapp
Stars: ✭ 46 (+64.29%)
Mutual labels:  flutter-plugin
appmetrica sdk
A Flutter plugin for Yandex AppMetrica SDK, a marketing platform for app install attribution, app analytics, and push campaigns.
Stars: ✭ 15 (-46.43%)
Mutual labels:  flutter-plugin
flutter-devicelocale
A Flutter package to read and return the set device locales
Stars: ✭ 45 (+60.71%)
Mutual labels:  flutter-plugin
flutter example
flutter code,flutter-banner,flutter-codekk,flutter-panda,flutter_tab
Stars: ✭ 94 (+235.71%)
Mutual labels:  flutter-plugin
flutter-crisp
Flutter plugin for Crisp Chat
Stars: ✭ 18 (-35.71%)
Mutual labels:  flutter-plugin
aeyrium-sensor
A Flutter sensor plugin which provide easy access to the Pitch and Roll on Android and iOS devices.
Stars: ✭ 57 (+103.57%)
Mutual labels:  flutter-plugin
getx snippets extension
An extension to accelerate the process of developing applications with flutter, aimed at everyone using the GetX package.
Stars: ✭ 142 (+407.14%)
Mutual labels:  flutter-plugin
flutter opencv
OpenCV bindings plugin for Flutter apps [work in progress]
Stars: ✭ 81 (+189.29%)
Mutual labels:  flutter-plugin
pub-scaff
scaff, scaffold generator for Dart and Flutter
Stars: ✭ 27 (-3.57%)
Mutual labels:  flutter-plugin
r scan
📷🖨Flutter二维码&条形码扫描插件,支持相机、文件、链接、Uint8List类型扫描
Stars: ✭ 108 (+285.71%)
Mutual labels:  flutter-plugin
flutter-elinux-plugins
Flutter plugins for embedded Linux (eLinux)
Stars: ✭ 21 (-25%)
Mutual labels:  flutter-plugin

theme_mode_handler

version All Contributors

Flutter widget to change themeMode during runtime and persist it across restarts.

Motivation

Flutter 1.9 introduced a new way to control which theme is used: MaterialApp.themeMode. If you have specified the darkTheme and theme properties, you can use themeMode to control it. The property defaults to ThemeMode.system.

This package wraps this functionality and allows you to persist and retrieve the user's preference wherever you want by implementing an interface.

Installation

Add this to your pubspec.yaml:

dependencies:
  theme_mode_handler: ^3.0.0

Usage

  • Create a class that implements the IThemeModeManager interface:
class MyManager implements IThemeModeManager {
  @override
  Future<String> loadThemeMode() async {}

  @override
  Future<bool> saveThemeMode(String value) async {}
}
  • Import the ThemeModeHandler widget, wrap MaterialApp with it and pass it an instance of your manager:
import 'package:theme_mode_handler/theme_mode_handler.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ThemeModeHandler(
      manager: MyManager(),
      builder: (ThemeMode themeMode) {
        return MaterialApp(
          themeMode: themeMode,
          darkTheme: ThemeData(
            brightness: Brightness.dark,
          ),
          theme: ThemeData(
            brightness: Brightness.light,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      },
    );
  }
}
  • Change the themeMode with:
ThemeModeHandler.of(context).saveThemeMode(value);
  • Get the current themeMode with:
ThemeModeHandler.of(context).themeMode;

Check the example folder for a complete example.

API

builder

Type: Widget Function(ThemeMode themeMode).

Function that runs when themeMode changes.

manager

Type: IThemeModeManager.

Implementation of IThemeModeManager to load and save the selected value.

defaultTheme

Type: ThemeMode.

Default value to be used when manager.loadThemeMode returns null or an invalid value.

placeholderWidget

Type: Widget?.

While the themeMode is loaded, you can choose to render a different widget. By default, it'll render an empty container.

Extra

This package exports a dialog and a method to simplify its usage.

  • Import the dialog with:
import 'package:theme_mode_handler/theme_picker_dialog.dart';
  • Use it like this:
void _selectThemeMode(BuildContext context) async {
  final newThemeMode = await showThemePickerDialog(context: context);
  print(newThemeMode);
}

Inspiration

This package is inspired and based on the great package dynamic_theme.

Contributors

Thanks goes to these wonderful people (emoji key):


Arthur Denner

💻 🎨 💡 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Arthur Denner

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].