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

easy_formz 封面
插件详情v1.1.4

easy_formz

用于更轻松处理表单生成器的 Flutter 插件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
50
喜欢数
4
Pub 分数
150

安装插件

flutter pub add easy_formz

插件介绍

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

Easy Formz 是一个 Flutter 包,旨在通过提供一种简化表单生成和验证的流畅方法来简化表单处理。它减少了样板代码,并通过直观的 API 提高了开发人员的生产力,用于管理表单状态、验证规则和提交逻辑。该包使用 Dart 编写,可无缝集成到跨多个平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)的 Flutter 应用中。该包通过利用不可变数据结构和响应式模式,促进代码的简洁性和可维护性。对于希望以最少的努力构建强大且可扩展的表单的开发者来说,它特别有用。

适合场景

  • 使用最少样板代码创建表单
  • 响应式表单状态管理
  • 跨平台表单实现
  • 复杂验证逻辑处理
  • 简化表单提交流程

主要特点

  • 不可变表单状态
  • 内置验证工具
  • 响应式表单更新
  • 对自定义验证器的支持
  • 与 Flutter 小部件的轻松集成

适合对象

  • 开发复杂表单的开发者
  • 注重代码可维护性的团队
  • 需要跨平台表单一致性的项目
  • 具有严格验证需求的应用程序
  • Flutter 初学者学习表单处理

使用建议

  • 需要理解响应式编程概念
  • 可能需要额外设置以支持高级验证场景
  • 最适合使用状态管理解决方案(如 Bloc 或 Provider)的项目
  • 除了基本示例外,文档有限
  • 不太适合非常简单的单次表单

原始 README

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

EasyFormz Package

The purpose of this package is to facilitate the creation of dynamic forms based on data received from the server. The package provides several basic components, including form types such as 'input', 'textarea', 'dropdown', 'checkbox', 'multicheckbox', 'radio', 'date', and 'time'. Additionally, users have the flexibility to create custom forms if none of the predefined form types suit their needs.

The example app running in iOS

Table of Contents

Available Form Types

  1. Input: Single-line text input.
  2. Textarea: Multi-line text input.
  3. Dropdown: Dropdown selection.
  4. Checkbox: Single checkbox.
  5. Multicheckbox: Multiple checkboxes.
  6. Radio: Radio button selection.
  7. Date: Date picker for selecting a date.
  8. Time: Time picker for selecting a time.

Using the EasyFormz Widget

To integrate the package into your Flutter application, follow these steps:

  1. Add the EasyFormz widget to your widget tree:

    EasyFormz(controller: controller)
    
  2. Initialize the form controller with the desired form data & Keep your UI in sync by listening to changes on the form controller. Example:

     late final EasyFormzController controller = EasyFormzController(forms: forms);
    
     @override
     Widget build(BuildContext context) {
       return Scaffold();
     }
    

    The forms data should be look like this

    final forms = [
     FormConfig(
       id: '412',
       type: 'input',
       formKey: 'dynamic_input_key',
       label: 'Test Form Input',
       props: FormProps(isRequired: true),
     ),
      FormConfig(
       id: '702',
       type: 'dropdown',
       formKey: 'dynamic_dropdown_key',
       label: 'Test Form Dropdown',
       props: FormProps(
         isRequired: true,
         options: [
           FormOption(label: 'Option One', value: 'ONE'),
           FormOption(label: 'Option Two', value: 'TWO'),
           FormOption(label: 'Option Three', value: 'Three'),
         ],
       ),
     ),
     FormConfig(
       id: '432',
       type: 'radio',
       formKey: 'dynamic_radio_key',
       label: 'Test Form Radio',
       props: FormProps(
         isRequired: false,
         options: [
           FormOption(label: 'Option One', value: 'ONE'),
           FormOption(label: 'Option Two', value: 'TWO'),
           FormOption(label: 'Option Three', value: 'THREE'),
         ],
       ),
     ),
     FormConfig(
       id: '612',
       type: 'checkbox',
       formKey: 'dynamic_checkbox_key',
       label: 'Test Form Checkbox',
       props: FormProps(
         isRequired: false,
         options: [
           FormOption(label: 'Option One', value: 'ONE'),
           FormOption(label: 'Option Two', value: 'TWO'),
           FormOption(label: 'Option Three', value: 'THREE'),
         ],
       ),
     ),
     FormConfig(
       id: '612',
       type: 'textarea',
       formKey: 'dynamic_textarea_key',
       label: 'Test Form Text Area',
       props: FormProps(isRequired: true),
     ),
     FormConfig(
       id: '232',
       type: 'checkbox',
       formKey: 'dynamic_checkboxNoOption_key',
       label: 'Test Form Checkbox No Option',
       props: FormProps(isRequired: true),
     ),
     FormConfig(
       id: '132',
       type: 'multicheckbox',
       formKey: 'dynamic_multiCheckbox_key',
       label: 'Test Form MultiCheckbox',
       props: FormProps(
         isRequired: true,
         options: [
           FormOption(label: 'Option One', value: 'ONE'),
           FormOption(label: 'Option Two', value: 'TWO'),
           FormOption(label: 'Option Three', value: 'THREE'),
         ],
       ),
     ),
     FormConfig(
       id: '162',
       type: 'date',
       formKey: 'dynamic_date_key',
       label: 'Test Form Date',
       props: FormProps(isRequired: false),
     ),
     FormConfig(
       id: '164',
       type: 'time',
       formKey: 'dynamic_time_key',
       label: 'Test Form Time',
       props: FormProps(isRequired: true),
     ),
    ];
    
  3. Let's say you have a list of form page then you can do like the following example:

    final formPages = [
        FormPage(
             id: 'gweorj29',
             label: 'Example Page 1',
             description: 'This form displays all the existing forms available',
             formConfigs: forms1,
         ),
            FormPage(
             id: 'gweorj29',
             label: 'Example Page 2',
             description: 'This form displays all the existing forms available',
             formConfigs: forms2,
         ),
    ];
    

    To diplay all the form pages as a ListTile

    ListView.separated(
         itemCount: formPages.length,
         separatorBuilder: (context, index) {
           return const SizedBox(height: 16);
         },
         itemBuilder: (context, index) {
           final form = formPages[index];
    
           return Card(
             margin: const EdgeInsets.symmetric(horizontal: 16),
             clipBehavior: Clip.antiAlias,
             child: ListTile(
               onTap: () {
                 Navigator.push(
                   context,
                   MaterialPageRoute(
                     builder: (context) => FormScreen(form: form),
                   ),
                 );
               },
               title: Text(
                 form.label,
                 style: Theme.of(context).textTheme.titleMedium,
               ),
               subtitle: Text(
                 form.description,
                 style: Theme.of(context).textTheme.bodySmall,
               ),
             ),
           );
         },
       ),
    

    Inside the FormScreen get the form parameter like the following example:

     late final EasyFormzController controller = EasyFormzController(forms: widget.form.formConfigs);
    
     @override
     Widget build(BuildContext context) {
       return Scaffold();
     }
    

Custom Form Creation

In scenarios where the provided form types do not meet specific requirements, users can easily create custom forms tailored to their needs.

Basic Component Builder

To change any in-built form component such as inputBuilder, etc, consider the following example:

EasyFormz(
controller: controller,
inputBuilder: (config, onValueChanged) => Padding(
 padding: const EdgeInsets.all(16),
 child: TextFormField(
   onChanged: (value) {
     onValueChanged(value);
   },
 ),
),
);
Custom Form Component Builder

To create a custom form component based on the form configuration using the customBuilder, consider the following example:

EasyFormz(
  controller: controller,
  customBuilder: (config, onValueChanged) {
    if (config.type == 'custom_form') {
      // Customize and return the specific custom form component based on the condition.
      return CustomDropdown(
        config: config,
        onChanged: (value) => onValueChanged(value),
      );
    }
  },
);
Custom Error Component Builder

Custom error component is available by using the errorBuilder, consider the following example:

EasyFormz(
  controller: controller,
  errorBuilder: (config) {
    return CustomErrorBox(
        label: '${config.label} cannot be rendered',
      );
  },
);
Customizing the Easy Form Theme

To personalize the appearance of the dynamic form, you can modify the theme settings using the theme parameter. Below is an example of customizing the theme for a EasyFormz:

EasyFormz(
  controller: controller,
  theme: EasyFormzTheme()
)

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.

License

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

Support Me

If you find this package helpful and want to support its development, consider making a donation. Thank you for your support!

Support via PayPal

所属分类

源码仓库

使用此插件的项目

暂无相关数据。