패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.1.0

form_field_validator

일반적인 검증 옵션을 제공하는 간단한 플러터 폼 필드 유효성 검사기입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.3만
좋아요
457
Pub 점수
140

패키지 설치

flutter pub add form_field_validator

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

일반적인 검증 규칙을 제공하여 폼 검증을 간소화하는 가벼운 플러터 패키지입니다. 필수 항목, 이메일 형식, 비밀번호 등 입력값을 확인하기 위한 사용이 쉬운 메서드를 제공합니다. 플러터 폼 위젯과 원활하게 통합되도록 설계되어 반복 코드를 줄이고 다양한 폼 필드에서 일관된 검증을 보장합니다. 이 패키지는 지속적으로 유지보수되며 Android, iOS, Web, macOS, Windows, Linux를 포함한 모든 주요 플랫폼을 지원합니다.

사용 사례

  • 사용자 등록 양식 검증
  • 이메일과 비밀번호 입력 확인 중
  • 필수 필드가 입력되었는지 확인
  • 사용자 정의 검증 로직 구현
  • 반응형 및 동적 양식 만들기

주요 기능

  • 사전 정의된 검증 규칙
  • 간단한 API 통합
  • 여러 플랫폼을 지원합니다
  • 사용자 정의 검증기용으로 확장 가능
  • 에러 메시지 지우기

적합한 대상

  • 초보자용 Flutter 개발자
  • 빠른 폼 검증이 필요한 프로젝트
  • 복잡한 입력 양식을 가진 앱
  • 개발 속도를 우선시하는 팀
  • 크로스플랫폼 모바일 및 웹 앱

고려 사항

  • 기본적으로 기본 검증에 제한됨
  • 사용자 정의 로직은 추가 구현이 필요할 수 있습니다
  • 매우 복잡한 검증 워크플로에 적합하지 않음

원본 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

소스 저장소

이 패키지를 사용하는 프로젝트