Skip to content

MoaidAlrazhy/flutter_validation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Validation is localized validation package wrapped around form_field_validator to deliver ready localized validation messages.

  1. Getting Started
  2. Validators
    1. Common
    2. Phone
      1. International
      2. National
    3. Match
    4. List
    5. Length
    6. Number
    7. Date
    8. Custom
  3. Multi Validator
  4. How does it work

Getting Started

  1. Add to your dependencies:
dependencies:
  flutter_validation:
    git: git://github.com/MoaidAlrazhy/flutter_validation.git
  1. Add localizations delegates in your MaterialApp widget:
MaterialApp(
	// ...
	localizationsDelegates: [
		ValidationLocalizations.delegate,
		AttributeLocalizations.delegate,
	],
	supportedLocales: [
		const Locale('en'),
		const Locale('ar'),
        const Locale.fromSubtags(languageCode: 'zh', countryCode: 'CN', scriptCode: 'Hans'),

/// add other locales for now (en, ar)
	],
	// ...
)
  1. Use it:
/// ...

TextFormField(
	decoration: InputDecoration(
		labelText: AttributeLocalizations.of(context).email,
	),
	// It's as easys as
	validator: Validator.of(context).email,
)

/// ...

Validators

Common

Validator.of(context).name // Validate name split legth >= 2
Validator.of(context).fullName // Validate name split legth >= 4
Validator.of(context).email // Validate email regex
Validator.of(context).required(
	AttributeLocalizations.of(context).name,
) // Validate name to be required
Validator.of(context).empty(
	AttributeLocalizations.of(context).name,
) // Validate name to be empty

Phone

International

Validator.of(context).phone

National

Validator.of(context).phoneNational(
	IsoCode.US
);

Match

Validator.of(context).match(
	AttributeLocalizations.of(context).password,
	AttributeLocalizations.of(context).passwordConfirmation,
	() => 'confirm_password',
);

List

Validator.of(context).contains(
	AttributeLocalizations.of(context).gender,
	[
		'male',
		'femaile',
	],
);

Length

Validator.of(context).length(
	AttributeLocalizations.of(context).password,
	3,
);

Validator.of(context).minLength(
	AttributeLocalizations.of(context).password,
	6,
);

Validator.of(context).minLength(
	AttributeLocalizations.of(context).password,
	12,
);

Number

Validator.of(context).lessThan(
	AttributeLocalizations.of(context).age,
	18,
);

Validator.of(context).lessThanOrEqualTo(
	AttributeLocalizations.of(context).age,
	18,
);

Validator.of(context).greaterThan(
	AttributeLocalizations.of(context).age,
	18,
);

Validator.of(context).greaterThanOrEqualTo(
	AttributeLocalizations.of(context).age,
	18,
);

Validator.of(context).isNum(AttributeLocalizations.of(context).price);

Validator.of(context).isInt(AttributeLocalizations.of(context).price);

Date

Validator.of(context).lessThan(
	AttributeLocalizations.of(context).age,
	18,
);

Custom

// Example for starts with `https`
Validator.of(context).pattern(
	'Url',
	r'^(http|https)://',
);

Multi Validator

As the package depend on form_field_validator so you can use the same logic using MultiValidator:

MultiValidator([
	Validator.of(context).required(
		AttributeLocalizations.of(context).name
	),
	Validator.of(context).name,
	// ...
])

How does it work

As the library delivers a localized validation so it depends on both of validation_localizations and attribute_localizations.

About

Flutter localized validation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 76.4%
  • HTML 10.3%
  • Ruby 9.3%
  • Swift 2.8%
  • Other 1.2%