搜尋套件、儲存庫與 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

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。