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

flutter_switch 封面
插件详情v0.3.2

flutter_switch

一个自定义开关小部件,可以具有自定义高度和宽度、边框、边框半径、颜色、切换大小、切换内部的自定义文本和图标。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
15.5万
喜欢数
634
Pub 分数
150

安装插件

flutter pub add flutter_switch

插件介绍

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

flutter_switch 是一个可自定义的开关小部件,适用于 Flutter,允许开发者调整尺寸、边框、圆角半径、颜色和切换大小。它支持在切换中自定义文本和图标,提供高度的视觉灵活性。非常适合在多个平台上创建具有定制设计的独特开/关控件。该包轻量且易于通过 pub.dev 集成。

适合场景

  • 自定义 UI 开关
  • 主题切换元素
  • 跨平台切换组件
  • 交互式表单控件
  • 增强的用户界面设计

主要特点

  • 可调节的高度和宽度
  • 自定义边框和圆角半径
  • 支持切换按钮中的图标和文本
  • 可配置的颜色和切换按钮大小
  • 跨平台兼容性

适合对象

  • 寻求自定义的UI设计师
  • 开发交互式表单的开发者
  • 需要品牌化切换开关的应用
  • 面向多个平台的项目
  • 注重一致UI元素的团队

使用建议

  • 需要手动处理状态管理
  • 有限的内置动画
  • 不适合复杂的动态切换
  • 可能需要额外的样式以满足可访问性要求
  • 依赖外部包以实现高级功能

原始 README

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

flutter_switch

All Contributors

pub package pub points popularity likes

An easy to implement custom switch created for Flutter. Give it a custom height and width, border for the switch and toggle, border radius, colors, toggle size, a choice to display an 'On' and 'Off' text and able to add an icon inside the toggle.

GitHub followers

Demo

flutter_switch

Video version: https://youtu.be/JqJnxjE6Efc

Use this package as a library

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_switch: ^0.3.1

You can install packages from the command line with Flutter:

$ flutter pub get

Import in your project:

import 'package:flutter_switch/flutter_switch.dart';

Sample Usage

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool status = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("FlutterSwitch Demo"),
      ),
      body: Center(
        child: Container(
          child: FlutterSwitch(
            width: 125.0,
            height: 55.0,
            valueFontSize: 25.0,
            toggleSize: 45.0,
            value: status,
            borderRadius: 30.0,
            padding: 8.0,
            showOnOff: true,
            onToggle: (val) {
              setState(() {
                status = val;
              });
            },
          ),
        ),
      ),
    );
  }
}

Want to Contribute?

Contributions to this project is very much welcome. Let's work together to maintain and improve the project Simply Fork the repository, Commit and Push your changes and create a new Pull Request.

Don't forget to try out the example project under the ./example folder.

Also test your changes by running this command.

$ flutter test

If you have some suggestions, you can reach me at romero.nicholejohn@gmail.com

License

BSD 3-Clause License

Copyright (c) 2020, Nichole John Romero
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

    3. Neither the name of the copyright holder nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Nickr

💻 📖 🚧 ⚠️

Lucas Eduardo

💻

Douglas Ramos

💻

Daniyil Yevtyushkin

💻 ⚠️

Maksim Nikolaev

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

所属分类

源码仓库

使用此插件的项目