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

multiselect_formfield 封面
插件详情v0.1.7

multiselect_formfield

使用警报对话框选择多个项目(带复选框),并以芯片形式显示的多选表单字段。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2360
喜欢数
139
Pub 分数
130

安装插件

flutter pub add multiselect_formfield

插件介绍

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

一个 Flutter 包,提供使用带有复选框的警报对话框进行多选表单字段。所选项目以芯片形式显示,提供一种简洁且交互性强的方式来处理表单中的多项选择。该包支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。通过结合直观的选择与芯片提供的视觉反馈,该包提升了用户体验,非常适合用于筛选、标签或基于偏好的输入。

适合场景

  • 需要多个选择的表单输入
  • 标签系统
  • 仪表板中的筛选选项
  • 用户偏好收集
  • 多选调查
  • 动态类别选择

主要特点

  • 带复选框的警告对话框
  • 芯片显示所选项目
  • 跨平台支持
  • 可自定义的对话框标题和按钮
  • 与 Form 小部件的轻松集成
  • 支持空安全

适合对象

  • 开发人员构建包含多个选项的表单
  • 需要标签或筛选功能的应用
  • 需要直观的多选用户界面的项目
  • 使用 Flutter 开发网页和桌面应用的团队
  • 以用户体验为中心的应用程序,带有交互式表单

使用建议

  • 可能需要为复杂主题自定义样式
  • 对话在小屏幕上可能具有干扰性
  • 复选框外观的自定义选项有限
  • 不适用于非常大的项目列表
  • 需要手动处理初始值
  • 最适合与中等数量的可选项目一起使用

原始 README

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

Donate - Buy Me A Coffee

Multi select form field

A multi select form field using alert dialog to select multiple items with checkboxes and showing as chips.

Demo

Features

  • Can be used as regular form field.
  • Simple to implement.
  • Simple and intuitive to use in the app.
  • Provides validation of data.
  • Provides requirement of the field.
  • Customizable texts.
  • Follows the app theme and colors.
  • Upgraded to Null Safety.
Customization Parameters [MultiFormField]
Parameter Description
title Widget Set Title of MultiSelectTextFormField.
hintWidget Widget Set Hint Text of MultiSelectTextFormField.
required bool Add Selection is Compulsary or not.
errorText String Error String to be Displayed
dataSource List List of Data as DataSource To Select.
textField String Key Param from List (DataSource).
valueField String Value Param From List (DataSource).
okButtonLabel String* POsitive Button Label String.
cancelButtonLabel String* Negative Button Label String.
fillColor Color Widget Changes background color of FormField
Customization [Selection Dialog]
Parameter Description
Shape ShapeBorder Customizes the Shape Of AlertDialog
dialogTextStyle TextStyle Customizes the TextStyle Of AlertDialog
checkBoxCheckColor Color Customizes the CheckColor
checkBoxActiveColor Color Customizes the CheckBoxActiveColor
Customization [Selection Chip]
Parameter Description
chipLabelStyle TextStyle Customizes the TextStyle Of Selected Chip
chipBackGroundColor Color Customizes the Color Of Selected Chip

Minimal Example

MultiSelectFormField(
                  autovalidate: false,
                  chipBackGroundColor: Colors.red,
                  chipLabelStyle: TextStyle(fontWeight: FontWeight.bold),
                  dialogTextStyle: TextStyle(fontWeight: FontWeight.bold),
                  checkBoxActiveColor: Colors.red,
                  checkBoxCheckColor: Colors.green,
                  dialogShapeBorder: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(12.0))),
                  title: Text(
                    "Title Of Form",
                    style: TextStyle(fontSize: 16),
                  ),
                  dataSource: [
                    {
                      "display": "Running",
                      "value": "Running",
                    },
                    {
                      "display": "Climbing",
                      "value": "Climbing",
                    },
                    {
                      "display": "Walking",
                      "value": "Walking",
                    },
                  ],
                  textField: 'display',
                  valueField: 'value',
                  okButtonLabel: 'OK',
                  cancelButtonLabel: 'CANCEL',
                  hintWidget: Text('Please choose one or more'),
                  initialValue: _myActivities,
                  onSaved: (value) {
                    if (value == null) return;
                    setState(() {
                      _myActivities = value;
                    });
                  },
                ),

Example

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage> {
  List? _myActivities;
  late String _myActivitiesResult;
  final formKey = new GlobalKey<FormState>();

  @override
  void initState() {
    super.initState();
    _myActivities = [];
    _myActivitiesResult = '';
  }

  _saveForm() {
    var form = formKey.currentState!;
    if (form.validate()) {
      form.save();
      setState(() {
        _myActivitiesResult = _myActivities.toString();
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('MultiSelect Formfield Example'),
      ),
      body: Center(
        child: Form(
          key: formKey,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Container(
                padding: EdgeInsets.all(16),
                child: MultiSelectFormField(
                  autovalidate: AutovalidateMode.disabled,
                  chipBackGroundColor: Colors.blue,
                  chipLabelStyle: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
                  dialogTextStyle: TextStyle(fontWeight: FontWeight.bold),
                  checkBoxActiveColor: Colors.blue,
                  checkBoxCheckColor: Colors.white,
                  dialogShapeBorder: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(12.0))),
                  title: Text(
                    "My workouts",
                    style: TextStyle(fontSize: 16),
                  ),
                  validator: (value) {
                    if (value == null || value.length == 0) {
                      return 'Please select one or more options';
                    }
                    return null;
                  },
                  dataSource: [
                    {
                      "display": "Running",
                      "value": "Running",
                    },
                    {
                      "display": "Climbing",
                      "value": "Climbing",
                    },
                    {
                      "display": "Walking",
                      "value": "Walking",
                    },
                    {
                      "display": "Swimming",
                      "value": "Swimming",
                    },
                    {
                      "display": "Soccer Practice",
                      "value": "Soccer Practice",
                    },
                    {
                      "display": "Baseball Practice",
                      "value": "Baseball Practice",
                    },
                    {
                      "display": "Football Practice",
                      "value": "Football Practice",
                    },
                  ],
                  textField: 'display',
                  valueField: 'value',
                  okButtonLabel: 'OK',
                  cancelButtonLabel: 'CANCEL',
                  hintWidget: Text('Please choose one or more'),
                  initialValue: _myActivities,
                  onSaved: (value) {
                    if (value == null) return;
                    setState(() {
                      _myActivities = value;
                    });
                  },
                ),
              ),
              Container(
                padding: EdgeInsets.all(8),
                child: ElevatedButton(
                  child: Text('Save'),
                  onPressed: _saveForm,
                ),
              ),
              Container(
                padding: EdgeInsets.all(16),
                child: Text(_myActivitiesResult),
              )
            ],
          ),
        ),
      ),
    );
  }
}

License

This project is licensed under the BSD License. See the LICENSE file for details.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。