pwd_field_validator 0.0.2
pwd_field_validator: ^0.0.2 copied to clipboard
With this package you can have a nice, cool and validated password text fields in your application.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:pwd_field_validator/pwd_field_validator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Password Validator Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Example(),
);
}
}
class Example extends StatefulWidget {
const Example({Key? key}) : super(key: key);
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
bool _validPassword = false;
final TextEditingController pwdController = TextEditingController();
String _passwordStrength = "";
final _formKey = GlobalKey<FormState>();
void _checkPasswordStrength(String password) {
if (password.length >= 8) {
setState(() {
_passwordStrength = "Strong";
});
} else if (password.length >= 4) {
setState(() {
_passwordStrength = "Medium";
});
} else {
setState(() {
_passwordStrength = "Weak";
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Password Validated Field"),
),
body: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_validPassword
? const Text(
"Password Valid!",
style: TextStyle(fontSize: 22.0),
)
: Container(),
PwdFieldValidator(
controller: pwdController,
onChanged: (password) {
_checkPasswordStrength(password);
},
), // password validated field from package
Text(
"Password Strength: $_passwordStrength",
style: const TextStyle(fontSize: 18.0),
),
// Button to validate the form
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
setState(() {
_validPassword = true;
});
} else {
setState(() {
_validPassword = false;
});
}
},
child: Text("Check password!")),
],
),
),
);
}
}
// Review changes here and commit or revert them