mhmzdev/password_validated_field
一個套件,讓您可以在應用程式中加入一個酷炫、美觀且經過驗證的密碼 TextFormField,以提升使用者體驗。此套件完全可自訂且容易修改。
- Stars
- 27
- Forks
- 6
- 最近推送(UTC)
- 2021年6月7日
- 專案狀態
- 未封存
技術主題
使用的依賴
依賴清單 2 項
- flutter
{"sdk":"flutter"} - flutter_test開發依賴
{"sdk":"flutter"}
原始 README
以下為英文專案原文快照,最新內容請造訪 GitHub。
展開 / 收合專案 README
A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully & easily modifiable.
Customizable Attributes
Import package:password_validated_field/src/requirement_widget.dart and following fields are modifiable:
inputDecorationtextEditingControllertextInputActiononEditCompleteonFieldSubmittedfocusNodecursorColortextStyleactiveIconinActiveIconactiveRequirementColorinActiveRequirementColor
👀 Here's how it looks
Below are few samples of what the package looks like.
Import the package and use package:password_validated_field/password_validated_field.dart
💻 Simple usage
https://user-images.githubusercontent.com/43790152/121000165-5683b180-c7a3-11eb-8a8f-5524dfa63291.gifclass Example extends StatefulWidget {
const Example({Key? key}) : super(key: key);
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
// simple check
bool _validPassword = false;
// form key
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Password Validated Field"),
),
body: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_validPassword
? Text(
"Password Valid!",
style: TextStyle(fontSize: 22.0),
)
: Container(),
PasswordValidatedFields(), // password validated field from package
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
setState(() {
_validPassword = true;
});
} else {
setState(() {
_validPassword = false;
});
}
},
child: Text("Check password!")),
],
),
),
);
}
}
Customized usage
https://user-images.githubusercontent.com/43790152/121000355-8e8af480-c7a3-11eb-8763-7ddf64fd48f2.gifclass CustomizeFieldExample extends StatefulWidget {
const CustomizeFieldExample({Key? key}) : super(key: key);
@override
_CustomizeFieldExampleState createState() => _CustomizeFieldExampleState();
}
class _CustomizeFieldExampleState extends State<CustomizeFieldExample> {
// simple check
bool _validPassword = false;
// form key
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Customized Field"),
),
body: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_validPassword
? Text(
"Password Valid!",
style: TextStyle(fontSize: 22.0),
)
: Container(),
PasswordValidatedFields(
inActiveIcon: Icons.cancel_outlined,
activeIcon: Icons.check,
inActiveRequirementColor: Colors.orange,
activeRequirementColor: Colors.green,
), // password validated field from package
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
setState(() {
_validPassword = true;
});
} else {
setState(() {
_validPassword = false;
});
}
},
child: Text("Check password!")),
],
),
),
);
}
}
More customized usage
https://user-images.githubusercontent.com/43790152/121000349-8cc13100-c7a3-11eb-865c-9b84c54f73a5.gifclass MoreCustomizedField extends StatefulWidget {
const MoreCustomizedField({Key? key}) : super(key: key);
@override
_MoreCustomizedFieldState createState() => _MoreCustomizedFieldState();
}
class _MoreCustomizedFieldState extends State<MoreCustomizedField> {
// simple check
bool _validPassword = false;
// form key
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Customized Field"),
),
body: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_validPassword
? Text(
"Password Valid!",
style: TextStyle(fontSize: 22.0),
)
: Container(),
PasswordValidatedFields(
inActiveIcon: Icons.cancel,
activeIcon: Icons.done_all,
inputDecoration: InputDecoration(
labelText: "Enter password",
filled: true,
fillColor: Colors.grey[300],
prefixIcon: Icon(Icons.lock),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.circular(10.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(10.0),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
borderRadius: BorderRadius.circular(10.0),
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
borderRadius: BorderRadius.circular(10.0),
),
),
), // password validated filed from package
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
setState(() {
_validPassword = true;
});
} else {
setState(() {
_validPassword = false;
});
}
},
child: Text("Check password!")),
],
),
),
);
}
}
🛠 Modifying the package
You can easily modify the package according to your need.
Major attributes to look for:
RegExpat the bottom of validated_fieldonChangecallBack in validated_fieldrequirement_widgetin requirement_widgetrequirement_widgetchecks added in validated_field
RegExp modification
- 1 Uppercase
RegExp(r'[A-Z]') - 1 lowercase
RegExp(r'[a-z]') - 1 numeric value
RegExp(r'[0-9]') - 1 special character
RegExp(r'[!@#$%^&*(),.?":{}|<>]') - 6 character length
_pass.length >= 6
Combine RegExp that you would need to modify along with the above mentioned:
RegExp(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{6,}$')
Complete Simple Example, here.