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

パッケージ詳細v1.1.0

form_field_validator

一般的な検証オプションを提供するシンプルなFlutterフォームフィールドバリデーター。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3.3万
いいね数
457
Pub ポイント
140

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

flutter pub add form_field_validator

パッケージ概要

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

一般的な検証ルールを提供することで、フォーム検証を簡素化する軽量なFlutterパッケージです。必須フィールド、メール形式、パスワードなど、入力をチェックするための使いやすいメソッドを提供しています。Flutterのフォームウィジェットとスムーズに統合できるように設計されており、ボイラープレートコードを減らしつつ、さまざまなフォームフィールド間で一貫した検証を保証します。このパッケージは積極的にメンテナンスされており、Android、iOS、Web、macOS、Windows、Linuxを含むすべての主要プラットフォームをサポートしています。

用途

  • ユーザー登録フォームの検証
  • メールアドレスとパスワードの入力を確認しています
  • 必須項目が入力されていることを確認する
  • カスタム検証ロジックの実装
  • 応答性と動的フォームの構築

主な機能

  • 事前定義された検証ルール
  • シンプルなAPI統合
  • 複数のプラットフォームをサポートしています
  • カスタムバリデーター用に拡張可能
  • エラーメッセージをクリアする

適している対象

  • 初心者向け Flutter 開発者
  • 迅速なフォーム検証を必要とするプロジェクト
  • 複雑な入力フォームを持つアプリ
  • 開発スピードを最優先するチーム
  • クロスプラットフォームモバイルおよびWebアプリ

注意事項

  • 標準では基本的な検証に制限されています
  • カスタムロジックには追加の実装が必要になる場合があります
  • 非常に複雑な検証ワークフローには適していない

元の README

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

form_field_validator

A straightforward flutter form field validator that provides common validation options.

Usage

     // assign it directly to a TextFormField validator  
     // you don't have the pass the value your self like  
     // validator: (value) => EmailValidator(errorText: 'invalid email address').call(value)  
       
     TextFormField(  
         validator: EmailValidator(errorText: 'enter a valid email address')  
         );  
   
     // create a reusable instance  
     final requiredValidator = RequiredValidator(errorText: 'this field is required');  
     
     // again assign it directly to the validator  
     TextFormField(validator: requiredValidator);  
     

Multi rules validation

   
  final passwordValidator = MultiValidator([  
    RequiredValidator(errorText: 'password is required'),  
    MinLengthValidator(8, errorText: 'password must be at least 8 digits long'),  
    PatternValidator(r'(?=.*?[#?!@$%^&*-])', errorText: 'passwords must have at least one special character')  
 ]);  
  
  String password;  
  
  Form(  
    key: _formKey,  
    child: Column(children: [  
      TextFormField(  
        obscureText: true,  
        onChanged: (val) => password = val,  
        // assign the the multi validator to the TextFormField validator  
        validator: passwordValidator,  
      ),  
  
      // using the match validator to confirm password  
      TextFormField(  
        validator: (val) => MatchValidator(errorText: 'passwords do not match').validateMatch(val, password),  
      )  
    ]),  
  );  
    

Make your own validator

   
class LYDPhoneValidator extends TextFieldValidator {  
  // pass the error text to the super constructor  
  LYDPhoneValidator({String errorText = 'enter a valid LYD phone number'}) : super(errorText);  
  
  // return false if you want the validator to return error  
  // message when the value is empty.  
  @override  
   bool get ignoreEmptyValues => true;  
    
	  @override  
	  bool isValid(String value) {  
	    // return true if the value is valid according the your condition  
	    return hasMatch(r'^((+|00)?218|0?)?(9[0-9]{8})$', value);  
	  }  
}  


   // use it by assigning it to the TextFormField validator  
   TextFormField(validator: LYDPhoneValidator());  


  
  
// you can also extend the base FieldValidator class   
// to work with non string values  
  
class CustomValidator extends FieldValidator<T>{  
   CustomValidator(String errorText) : super(errorText);  
  
	  @override  
	  bool isValid(T value) {  
	    // TODO: implement isValid  
	    return //condition;
	  }  
  }  
  

カテゴリー

依存関係

依存関係一覧 1 件

  • intl>=0.17.0 <=1.0.0

ソースリポジトリ

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