パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.1.1

formdator

フォームフィールドバリデータのコレクションで、コンポジションを通じて選択し、さまざまな組み合わせにグループ化できる — デコレータパターン。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
117
いいね数
28
Pub ポイント
150

パッケージをインストール

flutter pub add formdator

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Formdatorは、デコレーターパターンを使用して組み合わせることのできる柔軟なフォームフィールドバリデータのコレクションを提供するDartパッケージです。開発者が複数の検証ルールをスムーズに組み合わせられるようにし、フォーム間で再利用可能でモジュール化された検証ロジックを実現します。動的または複雑な入力検証が必要なアプリケーションに最適であり、モバイル、ウェブ、デスクトップなどさまざまなプラットフォームをサポートしています。このパッケージは、クリーンで組み合わせ可能なコードを重視し、Flutterのフォームエコシステムと簡単に統合できます。

用途

  • 動的フォーム検証
  • 複雑な入力ルール
  • 再利用可能な検証コンポーネント
  • クロスプラットフォームフォーム
  • カスタム検証チェーン
  • リアルタイムフィードバック

主な機能

  • 合成可能なバリデーター
  • デコレーターパターンの実装
  • Platform-agnostic
  • Flutter フォームとの簡単な統合
  • モジュール型設計
  • 拡張可能な検証ロジック

適している対象

  • 複雑なフォームを開発する開発者
  • 保守可能な検証コードが必要なチーム
  • 複数のルール検証を必要とするアプリ
  • クロスプラットフォーム要件を持つFlutterプロジェクト
  • コード再利用を重視するプロジェクト

注意事項

  • デコレータパターンの理解が必要です
  • シンプルなフォームの複雑さを増加させる可能性がある
  • 基本的な例以外のドキュメントは限られている
  • フォームウィジェット内の適切な設定に依存する

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

formdator

EO-Color logo

EO principles respected here DevOps By Rultor.com

pub license PDD status

build codecov CodeFactor Grade style: lint Hits-of-Code

Contents

Overview

Formdator — Formidable Validator.

Formdator is a fully object-oriented package for validating Flutter form fields. Its main benefits, compared to all other similar packages, include:

  • Dependency-free: there is only pure Dart code.
  • Object-oriented mindset: the elements for validation are immutable objects that can be combined in various configurations.
  • Classes with short — yet meaningful — names like Req for required fields; ReqEmail for non-empty, well-formed emails; Len for length constraints; Int for integer-only values; and so on.
  • Easy-to-compose validators: e.g., the command Trim(Email()) produces a validator that trims an email value before validating it.
  • Multiple validation at once: you can apply multiple validation rules at once by using the Pair or Rules classes.
  • Built-in set of compound validators: e.g., to validate an email and limit its length to a maximum of 50 characters, simply use an instance of Email.len(50) — write less; do more!

For easier integration with Flutter form fields, every validator implements the call() method. As a result, any validator object can be called as a function — Callable Classes.

Getting Started

The following code snippet demonstrates how you can easily group the Rules, Req, Len and Email classes together to create a kind of 'email-max-50-characters' constraint.

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      validator: Rules<String>([ // The "Rules" class performs multiple validations at once.
        Req(blank: 'Please enter the email'), // "blank" is the error message in case of field left blank.
        Len.max(50, long: 'Email length cannot exceed 50 characters'), // "long" is the error message if an input value is too long.
        Email(mal: 'Malformed email'), // "mal" is the error message in case of malformed email.
      ]),
    );
  }

Or — even better — use the compound validator ReqEmail to perform the same task.

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      validator: ReqEmail.len(
        50,
        blank: 'Please enter the email',
        mal: 'Malformed email',
        long: 'Email length cannot exceed 50 characters',
      ),
    );
  }

The shorter command ReqEmail.len(50) is equivalent to the much longer command Rules<String>([Req(), Len.max(50), Email()]) — write less; do more!

List of Validators

For a complete list of validators with detailed information about each one (constructors, parameters, etc.):

Grouped by Category
  • brazil — validators related to Brazil (BrMobile, BrPhone, Cep, Cnpj, Cpf, etc.).
  • core — core validators (Len, Match [text pattern], Pair, Req, Rules, Trim, etc.).
  • logic — validation logic and unit testing (Equal, Ok, Nok, ValueBack).
  • net — internet (Email, Ipv4, Ipv6, MacAddr, Url, etc.).
  • numeric — validators related to numbers or digits (Digit, Hex, Int, Num, etc.).

Demo application

The demo application provides a fully working example, focused on demonstrating exactly four validators in action — Pair, ReqLen, ReqEmail, and Equal. You can take the code in this demo and experiment with it.

To run the demo application:

  git clone https://github.com/dartoos-dev/formdator.git
  cd formdator/example/
  flutter run -d chrome

This should launch the demo application on Chrome in debug mode.

formdator-demo-app

Contribute

Contributors are welcome!

  1. Open an issue regarding an improvement, a bug you noticed, or ask to be assigned to an existing one.
  2. If the issue is confirmed, fork the repository, do the changes on a separate branch and make a Pull Request.
  3. After review and acceptance, the Pull Request is merged and closed.

Make sure the command below passes before making a Pull Request.

  dart analyze && sudo dart test

References

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト