搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。