Buscar categorias, pacotes e repositórios

Repositório GitHubmatthewrice345/theme_manager

theme_manager

Um gerenciador de temas para o Flutter que suporta temas claros, escuros e do sistema.

Capa do projeto theme_manager
Estrelas
7
Forks
1
Último push (UTC)
20 de fev. de 2024
Status do projeto
Ativo

README original

Texto original em inglês. Visite o GitHub para a versão atual.

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

run flutter packages get and import theme_manager

import 'package:theme_manager/theme_manager.dart';

A dialog is provided that can switch between themes.

import 'package:theme_manager/theme_picker_dialog.dart';

How to use

Make sure WidgetsFlutterBinding are initialized. This is required.

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

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(),
        );
      },
    );
  }
}

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);

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();
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.

Matthew Rice GitHub avatar
Autor no GitHub

Matthew Rice ↗

LinguagensDartRubyObjective-CJava

Pacotes publicados por este repositório

Dependências usadas

Lista de dependências 6 itens

Como escolher um repositório para seu projeto?

Filtre pelo caso de uso, compare a atividade e confira o projeto original antes de adotá-lo.

  1. Busque por nome, autor ou descrição e filtre por tema.
  2. Compare estrelas, forks e envios recentes. Estrelas indicam interesse, mas não garantem qualidade.
  3. Confira o README, a licença e as issues no GitHub antes de usar o projeto.

Fontes e manutenção

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗