Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

validation form inputs in Dart & Flutter

License

NotificationsYou must be signed in to change notification settings

novaday-co/inspection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Inspection Package

PubLicense: MIT


Inspection

WithInspection you can validate your inputs inFlutter &Dart likeLaravel Framework.

How to install :

Add this to your package's pubspec.yaml file:

dependencies:inspection:^0.0.14

Then You can install packages from the command line:

$ pub get

or

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Now in your Dart code, you can use:

import'package:inspection/inspection.dart';

Basic Usage :

You have a form , you want to validate inputs everyday in programming . WithInspection you can validate your inputs inDart likeLaravel Framework . See examples below .

You expect a required number with many conditions and rules :In this case , we get help fromInspection helper function .

TextFormField(    validator: (input)=>inspection(input,'required|numeric|between:2000,6000|contains:22,33,55|ends_with:0'),  ),

You can useInspection class :

TextFormField(    validator: (input)=>Inspection().inspect(input,'required|float'),  ),

And you can use helper function andInspection class withList of rules , so you can make a global validation configuration List and you can change your rules in whole of the application whenever you want.

TextFormField(    validator: (input)=>inspection(input, ['required','float']),  ),

or

TextFormField(    validator: (input)=>inspect(input, ['required','float']),  ),

Options :

You can set attributename , custommessage andlocale . For example :

TextFormField(    validator: (input)=>inspect(input,'required|float',message:'my custom message here !'),  ),

Rules :

RuleDescriptionExample
iran_national_codeInput must be a iranian national codeinspect(input,'iran_national_code')
have_alphaThe attribute must have alpha in itinspect(input,'have_alpha')
alpha_numThe attribute must contains only letters and numbersinspect(input,'alpha_num')
betweenThe attribute must be between :min and :maxinspect(input,'between:3,9')
containsThe attribute must contains one of your worldsinspect(input,'contains:farid,farhad')
emailThe attribute must be a valid emailinspect(input,'email')
ends_withThe attribute must ends with your patterninspect(input,'ends_with:bye')
gtThe attribute must grater than :gtinspect(input,'gt:10')
gteThe attribute must grater than or equal to :gteinspect(input,'gte:10')
hexThe attribute must be a valid hex codeinspect(input,'hex')
inThe attribute must be one of options in your listinspect(input,'in:farid,farhad,john')
ipThe attribute must be a valid IPinspect(input,'ip')
ltThe attribute must be less than :ltinspect(input,'lt:100')
lteThe attribute must be less than or equal to :lteinspect(input,'lte:100')
maxThe attribute must have maximum :max characterinspect(input,'max:10')
minThe attribute must have at least :min characterinspect(input,'min:3')
not_inThe attribute must not exists in list :not_ininspect(input,'not_in:saman,ahmad')
numericThe attribute must be a numberinspect(input,'numeric')
alphaThe attribute must contains only lettersinspect(input,'alpha')
floatThe attribute must be floatinspect(input,'float')
integerThe attribute must be integerinspect(input,'integer')
numberThe attribute must contains only numberinspect(input,'number')
regexThe attribute must match with regexinspect(input,'regex:^[a-zA-Z0-9]')
requiredThe attribute field is requiredinspect(input,'required')
starts_withThe attribute must starts with your patterninspect(input,'starts_with:hi')
urlThe attribute must be a valid urlinspect(input,'url')

Locales :

Inspection supports two languages now .English with code :en , andPersian with codefa andVietnamese with codevi. You can set locale when initializeinspection or in optional parameter ofinspect method. For example :

TextFormField(    validator: (input)=>Inspection(inspectionLocale:'fa').inspect(input,'required|in:farid,farhad'),  ),

or

TextFormField(    validator: (input)=>Inspection().inspect(input,'required|in:farid,farhad',locale:'fa'),  ),

Custom Rules :

You can simply extend fromInspection class and develop your custom rule . For example :

classCustomInspectionextendsInspection {StringmyCustomRule(ruleString, inspectionCase) {switch (ruleString) {case'myCustomRule':// Your conditional codes here or copy from a Rule class and change it to your own .returnMyCustomeRuleClass(inspectionCase).stringValidation();    }returnnull;  }}

Contribute :

You can help me and contribute for :

  • New rules
  • More locales
  • Better exceptions

[8]ページ先頭

©2009-2025 Movatter.jp