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

easy_dynamic_theme のカバー
パッケージ詳細v2.3.1

easy_dynamic_theme

OSで定義されたテーマ(ダイナミック)を自動的に取得し、お好みのテーマ(ライト/ダーク)を強制的に適用して、選択内容をデバイスに永続的に保存します。

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

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

flutter pub add easy_dynamic_theme

パッケージ概要

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

EasyDynamicTheme は、システムの推奨テーマ(ライトモードまたはダークモード)を自動的に検出することで、テーマ管理を簡素化するFlutterパッケージです。開発者は特定のテーマを強制的に適用でき、アプリ再起動後にユーザーの設定を永続化できます。Android、iOS、Web、macOS、Windows、Linuxなど、すべての主要プラットフォームをサポートしています。Flutterのテーマシステムとシームレスに統合され、ボイラープレートコードを減らし、適応型デザインによりユーザー体験を向上させます。ユーザー設定やデバイスの動作に基づいて一貫性があり、パーソナライズされたUIを提供したいアプリに最適です。

用途

  • システムテーマに基づくアダプティブUI
  • ユーザーのテーマ設定を保持する
  • ライトモードまたはダークモードを強制する
  • クロスプラットフォームのテーマの一貫性
  • 大規模なアプリでのテーマロジックの簡素化
  • アクセシビリティ機能のサポート

主な機能

  • 自動OSテーマ検出
  • 永続的なテーマストレージ
  • テーマの切り替えが簡単
  • すべてのFlutterプラットフォームをサポート
  • 最小限のセットアップが必要
  • 組み込みテーマプロバイダー

適している対象

  • 簡単なテーマ管理を求める開発者
  • ダークモード/ライトモード対応が必要なアプリ
  • 複数のプラットフォームをターゲットにするプロジェクト
  • ボイラープレートを減らしたいチーム
  • ユーザー体験に焦点を当てたアプリ
  • アクセシビリティに配慮したアプリケーション

注意事項

  • テーマの再構築を手動で処理する必要があります
  • 基本的なテーマを超えるカスタマイズは限られている
  • 実行時における動的テーマの更新をサポートしていません
  • 静的なテーマ選択を持つアプリに最適
  • 複雑なテーマのシナリオに対応するための追加ロジックが必要になる可能性があります
  • 永続化に shared_preferences に依存しています

元の README

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

Easy Dynamic Theme

This is a new and easy approach on Flutter Themes.

Automatically get your OS defined Theme (Dynamic), force your prefered one (Light / Dark) and persist your choice in the device.

Pub Version flutter tests Codacy Badge codecov GitHub BuyMeACoffee

Easy peasy, don't you think? ;)

Demo

Getting Started

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Minimum Requirements

  • Dart SDK: >=2.12.0 <3.0.0
  • Flutter: >= 1.20.0

Installation and Usage

Once you're familiar with Flutter you may install this package adding easy_dynamic_theme to the dependencies list
of the pubspec.yaml file as follow:

dependencies:  
  flutter: 
    sdk: flutter  
 easy_dynamic_theme: ^2.2.0

Then run the command flutter packages get on the console.

Examples of use

All magic occurs in your main.dart file

import 'package:flutter/material.dart';
import 'package:easy_dynamic_theme/easy_dynamic_theme.dart';
import 'home.dart';

void main() async { 
  runApp( 
    EasyDynamicThemeWidget( 
      child: MyApp(), 
    ), 
  );
}  
  
class MyApp extends StatelessWidget {  
  final String title = 'EDT - Example'; 
   
  @override 
  Widget build(BuildContext context) { 
    return MaterialApp( 
      title: title, 
      theme: ThemeData.light(), 
      darkTheme: ThemeData.dark(), 
      themeMode: EasyDynamicTheme.of(context).themeMode, 
      home: new MyHomePage(title: title,) 
    ); 
  }
}  
How to use predefined Themes

You can use your own themes as follows:

In the file themes.dart define your Themes

  import 'package:flutter/material.dart';
  
  var lightThemeData = new ThemeData(
      primaryColor: Colors.blue,
      textTheme: new TextTheme(button: TextStyle(color: Colors.white70)),
      brightness: Brightness.light,
      accentColor: Colors.blue);
  
  var darkThemeData = ThemeData(
      primaryColor: Colors.blue,
      textTheme: new TextTheme(button: TextStyle(color: Colors.black54)),
      brightness: Brightness.dark,
      accentColor: Colors.blue);

And then in your main.dart file import your themes file and use them on MaterialApp attributes theme and darkTheme

import 'package:flutter/material.dart';
import 'package:easy_dynamic_theme/easy_dynamic_theme.dart';
import 'theme.dart';
import 'home.dart';

void main() async { 
  runApp( 
    EasyDynamicThemeWidget( 
      child: MyApp(), 
    ), 
  );
}  
  
class MyApp extends StatelessWidget {  
  final String title = 'EDT - Example'; 
   
  @override
  Widget build(BuildContext context) { 
    return MaterialApp( 
      title: title, 
      theme: lightThemeData, 
      darkTheme: darkThemeData, 
      themeMode: EasyDynamicTheme.of(context).themeMode, 
      home: new MyHomePage(title: title,) 
    ); 
  }
}  
How to change the ThemeMode in your app

You can use the function changeTheme from anywhere in your app.

This function have two optional parameters: dynamic and dark. If the value of dynamic is true, it takes precedence over dark.

  EasyDynamicTheme.of(context).changeTheme();
How to get your app current theme
Current app ThemeMode
ThemeMode themeMode = EasyDynamicTheme.of(context).themeMode;  

The above example will return a value of the enum used by MaterialApp's ThemeMode with one of the following values:

system - Use either the light or dark theme based on what the user has selected in the system settings.

light - Always use the light mode regardless of system preference.

dark - Always use the dark mode (if available) regardless of system preference.

Current Context brightness
Brightness brightness = Theme.of(context).brightness;  

Or if you want to know if your widget is dark mode based, you can achieve it with:

bool isDarkModeOn = Theme.of(context).brightness == Brightness.dark;  
What about some out-of-the-box widgets?
Right now we have
  • EasyDynamicThemeBtn, which is (kind of) a FlatButton that displays the icon according to the current theme of your app and allows you to switch between them.
  • EasyDynamicThemeSwitch, which is a Switch widget, based on the current theme's brightness of your context and allows you to switch between light/dark them.
  • EasyDynamicThemeAutoSwitch, which is a Switch widget, based on the current theme of your app and allows you to prioritize (or not) your OS defined brightness.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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