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

所属分类

源码仓库

使用此插件的项目