Code Monkey home page Code Monkey logo

flutter_pw_validator's Introduction

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:

dependencies:
  flutter_pw_validator: <latest>

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,
    lowercaseCharCount: 2,
    numericCharCount: 3,
    specialCharCount: 1,
    width: 400,
    height: 150,
    onSuccess: yourCallbackFunction,
    onFail: yourCallbackFunction
)

Properties

Property Description Default Value Required
controller Takes your password TextField controller null Yes
minLength Takes total minimum length of password null Yes
uppercaseCharCount Takes minimum uppercase character count that has to include in the password 0 No
lowercaseCharCount Takes minimum lowercase character count that has to include in the password 0 No
numericCharCount Takes minimum numeric character count that has to include in the password 0 No
specialCharCount Takes minimum special character count that has to include in the password 0 No
width Takes the widget width null Yes
height Takes the widget height null Yes
onSuccess A void callback function that runs when the password is matched with the condition(s) null Yes
onFail A void callback that gets called everytime the password doesn't match with the condition(s) null No
defaultColor Takes default state color of the widget Color(0xFFd3d3d3) No
successColor Takes success state color of the widget Color(0xFF2ee292) No
failureColor Takes failure state color of the widget Color(0xFFf9433e) No
strings A class implementing the default FlutterPwValidatorStrings English FlutterPwValidatorStrings No
key Key to access the widget state and its functions GlobalKey<FlutterPwValidatorState>() null No

i18n

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

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

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

Example Project

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

flutter_pw_validator's People

Contributors

adithyaakrishna avatar arefmozafari avatar brunopereira-2331 avatar hugoheneault avatar jeffersonmello avatar money1998 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flutter_pw_validator's Issues

setState() called after dispose()

I have implemented the PW Validator and I am getting this error with every letter typed into the password field

======== Exception caught by foundation library ====================================================
The following assertion was thrown while dispatching notifications for TextEditingController:
setState() called after dispose(): _FlutterPwValidatorState#095a5(lifecycle state: defunct, not mounted)

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.

Improving Documentation Score

Description: The documnentation score of the package is 10/20 which can be improved by using documentation comments instead of normal comments

Screenshot:
image

- Normal Comment: //
- Documentation Comment: ///

Padding configurable

Hi,
There is a big padding between bars and text. Could we have a variable to specify this padding height ?
Rgds

Lowercase support

The issue #20 was closed, lowercase support was discarded?

it would be helpful to have this option

onFail method

Could you make an onFail option that runs every time the password doesn't match?

Why are Width and Height Required?

Why are width and height required? For a project I am working on it would be way more comfortable if the width and height would be automatically adjusted to the available space. Parameters like the height of the Validationbar, Paddings, TextSize etc could be passed in from the outside but have a sensible default.

Would you be open if I will open up a PR soon removing the fixed width and height?

setState() called after dispose()

I have made use of the widget in a form field when a user is registering for a new account like so

class PasswordValidator extends StatelessWidget {
  final TextEditingController controller;
  final Function() onSuccess;
  const PasswordValidator({
    Key? key,
    required this.controller,
    required this.onSuccess,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(
        left: 20.0,
        top: 0.0,
        right: 20.0,
        bottom: 20.0,
      ),
      child: FlutterPwValidator(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height * 0.2,
        minLength: 6,
        specialCharCount: 1,
        uppercaseCharCount: 1,
        numericCharCount: 1,
        onSuccess: onSuccess,
        controller: controller,
      ),
    );
  }
}

During the API call, I set the page to be replaced with a ProgressIndicator. When the API calls fails, the user is kept on the same page and the ProgressIndicator is removed and text form fields are reset, in resetting the controller value that the password field is bound to, the following error is thrown

The following assertion was thrown while dispatching notifications for TextEditingController:
setState() called after dispose(): _FlutterPwValidatorState#85b38(lifecycle state: defunct, not mounted)

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.

The above error is also thrown anytime the password field is tapped or interacted with at all.

Add i18n

Hey there!

It would be awesome if we could provide translation for hints.
I can craft a PR, is this OK for you?

I was thinking of renaming the Strings Class by a FlutterPwValidatorStrings and allowing to optionaly pass it to the FlutterPwValidator widget with a strings params. If not provided, use the default one.

Thanks alot!

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.