搜索插件、代码仓与 APP 分类

sliding_switch 封面
插件详情v1.1.0

sliding_switch

滑动开关 - 一个简单的开关小部件。它可以完全自定义宽度、颜色、文本等。它还保持选中状态。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
731
喜欢数
33
Pub 分数
130

安装插件

flutter pub add sliding_switch

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

SlidingSwitch 是一个可自定义的开关小部件,适用于 Flutter,允许用户通过滑动操作在两个状态之间切换。它支持对宽度、颜色、文本标签和动画进行完全自定义。该小部件在重建时保持其选择状态,确保用户体验的一致性。设计简洁且灵活,可在 Android、iOS、Web、macOS、Windows 和 Linux 平台上无缝运行。非常适合用于应用程序中的设置、偏好和开/关切换。

适合场景

  • 用户偏好切换
  • 设置面板
  • 开关
  • 表单控件
  • 深色模式切换

主要特点

  • 完全可自定义的外观
  • 状态持久化
  • 跨平台支持
  • 平滑滑动动画
  • 文本标签支持
  • 可配置的宽度和颜色

适合对象

  • 简单的切换UI
  • 可自定义表单元素
  • 跨平台应用
  • 偏好设置
  • 轻量级开关组件

使用建议

  • 仅限两态切换
  • 无内置的可访问性功能
  • 在复杂场景中需要手动处理状态
  • 不适用于多选项选择

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

sliding_switch

Sliding Switch - A simple switch widget. It can be fully customized with desired width, colors, text etc. It also maintains selection state.

Live Demo (Codeapprun)

codeapprun.io

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  sliding_switch: "latest"

Import it:

import 'package:sliding_switch/sliding_switch.dart';

Usage Examples

Minimum sliding switch configuration
SlidingSwitch(
 value: false,
 width: 250,
 onChanged: (bool value) {
   print(value);
 },
)

sliding switch

sliding switch other configurations
SlidingSwitch(
 value: false,
 width: 250,
 onChanged: (bool value) {
   print(value);
 },
 height : 55,
 animationDuration : const Duration(milliseconds: 400),
 onTap:(){},
 onDoubleTap:(){},
 onSwipe:(){},
 textOff : "Female",
 textOn : "Male",
 iconOff: Icons.human-female,
 iconOn: Icons.human-male,
 contentSize: 17,
 colorOn : const Color(0xffdc6c73),
 colorOff : const Color(0xff6682c0),
 background : const Color(0xffe4e5eb),
 buttonColor : const Color(0xfff7f5f7),
 inactiveColor : const Color(0xff636f7b),
),

If iconOn or iconOff are not null, they will be displayed in lieu of the respective textOn and textOff. The values for textOn and textOff are used as semantic labels for the icons for accessibility. The icons in the example are not in the default material icon set, but are from [Material Design Icons] (https://materialdesignicons.com/), available on pub.dev here.

contentSize drives the height of the text or icons.

Licensed Under the MIT License.

Inspiration

Jitu Raut

所属分类

源码仓库

使用此插件的项目

暂无相关数据。