Flutter Password Validator

License Pub Version GitHub stars

Flutter Password Validator package helps you to validate sign-in user-entered passwords with your rules.

How to use

1- Depend on it

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

  flutter_pw_validator: ^1.4.2

2- Install it

Install packages from the command line:

flutter pub get

3- Usage

First You have to import the file:

import 'package:flutter_pw_validator/flutter_pw_validator.dart';

And then just put it right under your password TextField and pass the controller to that:

new TextField(
    controller: _passwordController
new FlutterPwValidator(
    controller: _passwordController,
    minLength: 6,
    uppercaseCharCount: 2,
    numericCharCount: 3,
    specialCharCount: 1,
    width: 400,
    height: 150,
    onSuccess: yourCallbackFunction,
    onFail: yourCallbackFunction


PropertyDescriptionDefault ValueRequired
controllerTakes your password TextField controllernullYes
minLengthTakes total minimum length of passwordnullYes
uppercaseCharCountTakes minimum uppercase character count that has to include in the password0No
numericCharCountTakes minimum numeric character count that has to include in the password0No
specialCharCountTakes minimum special character count that has to include in the password0No
widthTakes the widget widthnullYes
heightTakes the widget heightnullYes
onSuccessA void callback function that runs when the password is matched with the condition(s)nullYes
onFailA void callback that gets called everytime the password doesn't match with the condition(s)nullNo
defaultColorTakes default state color of the widgetColor(0xFFd3d3d3)No
successColorTakes success state color of the widgetColor(0xFF2ee292)No
failureColorTakes failure state color of the widgetColor(0xFFf9433e)No
stringsA class implementing the default FlutterPwValidatorStringsEnglish FlutterPwValidatorStringsNo


If you want to translate this plugin simply implements the FlutterPwValidatorStrings class and pass it to the widget.

class FrenchStrings implements FlutterPwValidatorStrings {
  final String atLeast = 'Au moins - caractères';
  final String uppercaseLetters = '- Lettres majuscules';
  final String numericCharacters = '- Chiffres';
  final String specialCharacters = '- Caractères spéciaux';

    // ...
    // your config above
    strings: FrenchStrings()

Example Project

You can use this example project to see how it works.