カテゴリー・パッケージ・リポジトリを検索

GitHub リポジトリmatthewrice345/theme_manager

theme_manager

ライト、ダーク、システムテーマをサポートするFlutter用のテーママネージャー。

theme_manager のプロジェクト画像
スター
7
フォーク
1
最終プッシュ(UTC)
2024/02/20
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

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
GitHub 作者

Matthew Rice ↗

言語DartRubyObjective-CJava

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 6 件

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

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

GitHub Docs — About repositories ↗