Git Product home page Git Product logo

flutter_validation-master's Introduction

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/ysys-co/flutter_validation-master.git
  1. Add localizations delegates in your MaterialApp widget:
MaterialApp(
	// ...
	localizationsDelegates: [
		ValidationLocalizations.delegate,
		AttributeLocalizations.delegate,
	],
	supportedLocales: [
		const Locale('en'),
		const Locale('ar'),
		/// 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.

flutter_validation-master's People

Contributors

ysysco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.