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

light_dark_theme_toggle 封面
套件詳情v1.1.2

light_dark_theme_toggle

一個可動畫、可自訂的 Flutter 小部件,用於在亮色模式和暗色模式之間切換,並帶有視覺上吸引人的切換按鈕。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
184
喜歡數
16
Pub 分數
160

安裝套件

flutter pub add light_dark_theme_toggle

套件介紹

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

一個視覺上吸引人、帶有動畫效果的 Flutter 小部件,可實現明暗主題之間的無縫切換。設計時注重自定義,提供流暢的過渡效果和現代化的切換介面,適用於任何需要主題偏好的應用程式。該套件支援多個平台,並可輕鬆整合到現有專案中。它透過最少的設定,為使用者提供直觀的主題控制,從而提升使用者體驗。

適用情境

  • 應用主題偏好設定
  • 帶有動態照明模式的使用者介面
  • 透過主題切換增強可及性
  • 為開發者提供的可自定義 UI 組件
  • 跨平台主題切換

主要特色

  • 動畫主題轉換
  • 高度可自訂的外觀
  • 支援所有主要平台
  • 與 Flutter 應用的簡單整合
  • 輕量且高效

適合對象

  • 開發具有主題選項的應用程式的開發者
  • 尋求精緻UI元素的設計人員
  • 需要響應式深色/淺色模式的專案
  • 針對多元使用者偏好之應用
  • 跨平台移動和網頁應用

使用建議

  • 需要手動處理主題狀態的持久化
  • 僅限基本切換功能
  • 無內建系統主題檢測支援
  • 自定樣式可能需要額外的程式碼
  • 依賴外部主題管理邏輯

原始 README

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

LightDarkThemeToggle

The LightDarkThemeToggle widget is a customizable and animated light/dark theme toggle switch for Flutter apps. It provides a visually appealing way for users to switch between light and dark modes in your app.

Features

  • Customizable size, color, padding, and tooltip.
  • Smooth animations with adjustable duration and curves.
  • Multiple animated icon styles using different theme icon types.
  • Built entirely with Dart code and CustomPainter for efficient rendering and better performance.

Demo

LightDarkThemeToggle Web App

Preview

LightDarkThemeToggle Demo


Installation

  1. Add the dependency to your pubspec.yaml:
dependencies:
  light_dark_theme_toggle: ^1.1.2
  1. Import the package in your Dart file:
import 'package:light_dark_theme_toggle/light_dark_theme_toggle.dart';

Usage

Here is an example of how to use the LightDarkThemeToggle widget:

import 'package:flutter/material.dart';
import 'package:light_dark_theme_toggle/light_dark_theme_toggle.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      themeMode: ThemeMode.system,
      home: Scaffold(
        appBar: AppBar(title: Text('Light/Dark Theme Toggle')),
        body: Center(
          child: LightDarkThemeToggle(
            value: false,
            // Initial value (false for dark, true for light)
            onChanged: (bool value) {
              // Handle theme change here.
            },
            size: 48.0,
            themeIconType: ThemeIconType.expand,
            color: Colors.orange,
            tooltip: 'Toggle Theme',
            duration: Duration(milliseconds: 500),
            curve: Curves.easeInOut,
          ),
        ),
      ),
    );
  }
}

Properties

Property Type Default Description
value bool Required Determines whether the toggle is in light (true) or dark (false) mode.
onChanged ValueChanged<bool> Required Callback when the toggle is pressed.
themeIconType ThemeIconType ThemeIconType.expand Defines the style of the icon.
color Color? ThemeData.colorScheme.onSurface Color of the icon.
hoverColor Color? ThemeData.hoverColor Hover Color of the toggle.
highlightColor Color? ThemeData.highlightColor Highlight Color of the toggle in pressed down state.
focusColor Color? ThemeData.focusColor Focus Color of the toggle when it has input focus.
splashColor Color? ThemeData.splashColor Splash Color of the toggle.
tooltip String? null Tooltip displayed on long press or hover.
padding EdgeInsetsGeometry? null Padding around the icon.
size double? IconTheme.size ?? 24.0 Size of the icon.
duration Duration Duration(milliseconds: 500) Duration of the animation.
reverseDuration Duration Duration(milliseconds: 500) Duration of the reverse animation.
curve Curve Curves.easeOutBack Animation curve for the forward animation.
reverseCurve Curve Curves.easeOutBack Animation curve for the reverse animation.

Theme Icon Types

The widget supports the following icon types via the ThemeIconType enum:

  • Classic
  • Simple
  • Eclipse
  • HalfSun
  • DarkSide
  • InnerMoon
  • Expand
  • DarkInner

To use an icon type, pass it to the themeIconType property. For example:

LightDarkThemeToggle(
  themeIconType:ThemeIconType.eclipse,
  ...
)

Customization

Animation

You can adjust the animation by changing:

  • duration: Duration of the forward animation.
  • reverseDuration: Duration of the reverse animation.
  • curve: Curve for forward animation.
  • reverseCurve: Curve for reverse animation.
Appearance

You can customize the icon's:

  • size: Adjust the size of the toggle.
  • padding: Add padding around the icon.
  • tooltip: Set a tooltip message for accessibility.
  • color: Change the icon's color.
  • hoverColor: Change the toggle's color in hovering state.
  • focusColor: Change the toggle's color when it has the input focus.
  • highlightColor: Change the toggle's color in pressed down state.
  • splashColor: Change the toggle's splash color.

License

This project is licensed under the MIT License.


Contributions

Contributions, issues, and feature requests are welcome! Feel free to check out the issues page.


Author

Vivek Chib


Acknowledgments

This package is inspired by toggles.dev created by Alfie Jones.
Special thanks for providing inspiration and ideas that helped shape this package.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。