搜尋套件、儲存庫與 APP 分類

animated_theme_switcher 封面
套件詳情v2.0.10

animated_theme_switcher

Flutter 動畫主題切換器,可幫助建立美觀的主題切換動畫。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2740
喜歡數
533
Pub 分數
140

安裝套件

flutter pub add animated_theme_switcher

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可在切換亮色與暗色主題時實現順暢、動畫化的過渡效果。它透過提供視覺上吸引人的主題變更,避免突兀的視覺跳躍,從而提升使用者體驗。專為希望以最少程式碼實現優雅主題切換的開發者設計。此套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 與 Linux。它可與 Flutter 的主題系統無縫整合,並允許自訂動畫持續時間、曲線與過渡效果。

適用情境

  • 移動應用中的平滑主題過渡
  • 透過動畫主題變更增強使用者介面/體驗
  • 實現帶有視覺魅力的深色模式
  • 使用動態主題創建響應式設計
  • 透過漸進的主題變換支援可存取性

主要特色

  • 動畫主題轉換
  • 可自定的動畫持續時間和曲線
  • 跨平台相容性
  • 與 ThemeData 的輕鬆整合
  • 支援淺色和深色模式
  • 所需的最小樣板程式碼

適合對象

  • 尋求精緻UI過渡效果的應用程式開發者
  • 注重設計的 Flutter 項目
  • 頻繁切換主題的應用
  • 開發者優先考慮使用者體驗
  • 需要平台級主題一致性的項目

使用建議

  • 可能影響低階裝置的效能
  • 需要仔細調整動畫參數
  • 僅限主題相關動畫
  • 不適用於非主題狀態變更
  • 依賴 Flutter 的主題系統以實現完整功能

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

animated_theme_switcher

Pub

Animated theme switcher.

This library starts from Peyman's stackoverflow question how-to-add-animation-for-theme-switching-in-flutter

demo

Getting started

Add animated_theme_switcher: "^2.0.8" in your pubspec.yaml dependencies.

dependencies:
 animated_theme_switcher: "^2.0.8"
How To Use

Import the following package in your dart file

import 'package:animated_theme_switcher/animated_theme_switcher.dart';

Wrap MaterialApp with ThemeProvider widget, as it has shown in the following example:

  ThemeProvider(
      initTheme: initTheme,
      builder: (context, myTheme) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: myTheme,
          home: MyHomePage(),
        );
      }),
    ),

But if all you want is to provide a theme, use as follows:

  ThemeProvider(
      initTheme: initTheme,
      child: SomeCoolPage(),
    ),

Wrap the screen where you whant to make them switch with ThemeSwitchingArea widget, as it has shown in the following example:

    ThemeSwitchingArea(
      child: Builder(builder: (context) {
        return ...,
      },
    );

Wrap every switcher with ThemeSwitcher builder, and use ThemeSwitcher.of(context).changeTheme function to switch themes;


    ThemeData newTheme = ThemeData(
      primaryColor: Colors.amber
    );
    ...
    ThemeSwitcher(
      builder: (context) {
        ...
        onTap: () => ThemeSwitcher.of(context).changeTheme(
          theme: newTheme,
          isReversed: false // default: false 
        );
        ...
      },
    );

Alternatively you could use ThemeSwitcher.switcher() or ThemeSwitcher.withTheme().
Builders of this constructors already provide you ThemeSwitcher.
ThemeSwitcher.withTheme() also provides current theme:

    ThemeSwitcher.switcher(
      builder: (context, switcher) {
        ...
        onTap: () => switcher.changeTheme(
          theme: newTheme,
        );
        ...
      },
    );
    
    ThemeSwitcher.withTheme(
      builder: (context, switcher, theme) {
        ...
        onTap: () => switcher.changeTheme(
          theme: theme.brightness == Brightness.light
              ? darkTheme
              : lightTheme,
        );
        ...
      },
    );

Use optional named parameter clipper to pass the custom clippers.

    ...
    ThemeSwitcher(
      clipper: ThemeSwitcherBoxClipper(),
      builder: (context) {
        ...
      },
    );

Notes:

  1. This package is not intended to persist selected theme on the local device. But we added special example to show how to do it using shared_preferences package.

  2. Use the CanvasKit rendering engine to use it on web, more about it..

所屬分類

原始碼儲存庫

使用此套件的專案