パッケージ、リポジトリ、アプリカテゴリを検索

dynamic_themes のカバー
パッケージ詳細v1.1.0

dynamic_themes

ユーザーが選択できる色テーマの数を指定できます。アプリの再起動後に選択されたテーマが保持されます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
2710
いいね数
43
Pub ポイント
150

パッケージをインストール

flutter pub add dynamic_themes

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Dynamic Themes は、開発者がカスタマイズ可能な色のテーマを実装できるようにする Flutter パッケージです。ユーザーは複数の事前に定義されたテーマから選択して切り替えることができます。アプリの再起動後もユーザーが選択したテーマを自動的に保持し、一貫した体験を提供します。このパッケージは Android、iOS、Web、macOS、Windows、Linux などすべての主要プラットフォームをサポートしており、ダイナミックなテーマ機能を必要とするクロスプラットフォームアプリに最適です。

用途

  • ユーザーが選択可能なライトモードとダークモードのアプリ
  • 単一アプリケーション内のマルチテーマ対応
  • アプリ再起動後の永続的なテーマ設定
  • クロスプラットフォームのテーマの一貫性
  • カスタムブランドカラーのスケーム
  • ユーザーの好みの保持

主な機能

  • 簡単なテーマ設定
  • 自動テーマの永続化
  • すべてのFlutterプラットフォームをサポート
  • テーマ切り替えのためのシンプルな API
  • 組み込みのライト/ダークモードプリセット
  • 拡張可能なテーマシステム

適している対象

  • カスタマイズ可能なUIテーマを持つアプリを開発する開発者
  • 複数のプラットフォームをターゲットにするアプリ
  • 永続的なユーザーの好みを必要とするプロジェクト
  • ブランドカラーのパレットを使用したデザインシステム
  • ユーザー体験とアクセシビリティに焦点を当てたアプリケーション

注意事項

  • テーマカラーの手動設定が必要です
  • 事前に定義されたテーマセットに限定
  • 実行時テーマの生成なし
  • テーマの切り替えには再ビルドが必要な場合があります
  • 永続化のため共有設定に依存
  • 非常に大きなテーマコレクションには最適化されていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

dynamic_themes

"Buy Me A Coffee"

Dynamically change between multiple themes

This package allows you to specify multiple themes for the user to choose from. The theme can be updated dynamically during runtime. The package persits the selected theme across app restarts.

image

Getting Started

Follow the instructions here.

Usage

This package allows for an arbitrary number of themes to be defined. Each theme has a unique ID of type int. To create the themes and map them to IDs, first you have to create an instance of ThemeCollection, e. g.:

final themeCollection = ThemeCollection(
    themes: {
        0: ThemeData(primarySwatch: Colors.blue),
        1: ThemeData(primarySwatch: Colors.red),
        2: ThemeData.dark(),
    },
    fallbackTheme: ThemeData.light(), // optional fallback theme, default value is ThemeData.light()
);

However, I would recommend to introduce a class with static const int values to associate a name to each ID value:


class AppThemes {
    static const int LightBlue = 0;
    static const int LightRed = 1;
    static const int Dark = 2;
}
final themeCollection = ThemeCollection(
    themes: {
        AppThemes.LightBlue: ThemeData(primarySwatch: Colors.blue),
        AppThemes.LightRed: ThemeData(primarySwatch: Colors.red),
        AppThemes.Dark: ThemeData.dark(),
    },
    fallbackTheme: ThemeData.light(),
);

Now, wrap your material app like this:

return DynamicTheme(
    themeCollection: themeCollection,
    defaultThemeId: AppThemes.LightBlue, // optional, default id is 0
    builder: (context, theme) {
        return MaterialApp(
            title: 'dynamic_themes example',
            theme: theme,
            home: HomePage(title: 'dynamic_themes example app'),
        );
    }
);

The theme can be set anywhere in the app, provided you have a BuildContext, e. g.:

DynamicTheme.of(context).setTheme(AppThemes.LightRed);

By setting the theme, its ID is automatically saved via the shared_preferences package, so the next time the app starts, the theme can be restored automatically.

Provided you have wrapped the MaterialApp in the DynamicTheme widget, you can access the current theme like you are used to it by calling

final theme = Theme.of(context);

If for any reason you can't access the theme this way, you can also call

final theme = DynamicTheme.of(context).theme;

To get the ID of the current theme, for example to create a selection UI as done in the example app provided with this package, call

final themeId = DynamicTheme.of(context).themeId;

Example

The example app can be found in the example folder. It implements a dropdown menu to select between 4 themes. The app is the source for the screenshots above.

Maintainer

If you experience any problems using this package, please create an issue on Github. Pull requests are also very welcome.

Many thanks to the dynamic_theme package from Norbert Kozsir this package was inspired by!

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。