mirror of
https://github.com/Iconica-Development/flutter_input_library.git
synced 2025-05-18 17:03:45 +02:00
Merge pull request #28 from Iconica-Development/feat/password_decoration
feat(password): Provide a decoration to the password field
This commit is contained in:
commit
8eb1d80a9f
3 changed files with 20 additions and 13 deletions
|
@ -57,3 +57,6 @@
|
|||
|
||||
## 2.6.1
|
||||
* Addition of 'obscureText' parameter to 'FlutterFormInputPlainText'
|
||||
|
||||
## 2.7.0
|
||||
* Addition of 'decoration' parameter to 'FlutterFormInputPassword'
|
|
@ -18,6 +18,7 @@ class FlutterFormInputPassword extends StatefulWidget {
|
|||
final Function(String?)? onChanged;
|
||||
final Function(String?)? onFieldSubmitted;
|
||||
final bool enabled;
|
||||
final InputDecoration? decoration;
|
||||
|
||||
const FlutterFormInputPassword({
|
||||
Key? key,
|
||||
|
@ -31,6 +32,7 @@ class FlutterFormInputPassword extends StatefulWidget {
|
|||
this.onChanged,
|
||||
this.onFieldSubmitted,
|
||||
this.enabled = true,
|
||||
this.decoration,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -42,6 +44,18 @@ class _PasswordTextFieldState extends State<FlutterFormInputPassword> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var suffixIcon = IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscured = !obscured;
|
||||
});
|
||||
},
|
||||
icon: Icon(obscured ? Icons.visibility_off : Icons.visibility),
|
||||
);
|
||||
|
||||
var decoration = widget.decoration?.copyWith(suffixIcon: suffixIcon) ??
|
||||
InputDecoration(suffixIcon: suffixIcon);
|
||||
|
||||
return TextFormField(
|
||||
style: widget.style,
|
||||
initialValue: widget.initialValue,
|
||||
|
@ -52,17 +66,7 @@ class _PasswordTextFieldState extends State<FlutterFormInputPassword> {
|
|||
validator: (value) => widget.validator?.call(value),
|
||||
onChanged: (value) => widget.onChanged?.call(value),
|
||||
onFieldSubmitted: (value) => widget.onFieldSubmitted?.call(value),
|
||||
decoration: InputDecoration(
|
||||
label: widget.label ?? const Text("Password"),
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscured = !obscured;
|
||||
});
|
||||
},
|
||||
icon: Icon(obscured ? Icons.visibility_off : Icons.visibility),
|
||||
),
|
||||
),
|
||||
decoration: decoration,
|
||||
enabled: widget.enabled,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_input_library
|
||||
description: A new Flutter package project.
|
||||
version: 2.6.1
|
||||
version: 2.7.0
|
||||
repository: https://github.com/Iconica-Development/flutter_input_library
|
||||
|
||||
environment:
|
||||
|
|
Loading…
Reference in a new issue