Skip to content

Commit a5a0462

Browse files
committed
feat: create shared password component with toggle
1 parent d67dc94 commit a5a0462

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// Internal password field component with visibility toggle
4+
class SupaPasswordField extends StatefulWidget {
5+
/// Controller for the password field
6+
final TextEditingController controller;
7+
8+
/// Validator function for the password field
9+
final String? Function(String?)? validator;
10+
11+
/// Label text for the password field
12+
final String labelText;
13+
14+
/// Prefix icon for the password field
15+
final Widget? prefixIcon;
16+
17+
/// Autofill hints for the password field
18+
final Iterable<String>? autofillHints;
19+
20+
/// Text input action for the password field
21+
final TextInputAction? textInputAction;
22+
23+
/// Callback when field is submitted
24+
final void Function(String)? onFieldSubmitted;
25+
26+
/// Whether the field should auto-validate
27+
final AutovalidateMode? autovalidateMode;
28+
29+
const SupaPasswordField({
30+
super.key,
31+
required this.controller,
32+
this.validator,
33+
required this.labelText,
34+
this.prefixIcon,
35+
this.autofillHints,
36+
this.textInputAction,
37+
this.onFieldSubmitted,
38+
this.autovalidateMode,
39+
});
40+
41+
@override
42+
State<SupaPasswordField> createState() => _SupaPasswordFieldState();
43+
}
44+
45+
class _SupaPasswordFieldState extends State<SupaPasswordField> {
46+
bool _obscureText = true;
47+
48+
@override
49+
Widget build(BuildContext context) {
50+
return TextFormField(
51+
controller: widget.controller,
52+
validator: widget.validator,
53+
obscureText: _obscureText,
54+
autofillHints: widget.autofillHints,
55+
textInputAction: widget.textInputAction,
56+
onFieldSubmitted: widget.onFieldSubmitted,
57+
autovalidateMode: widget.autovalidateMode,
58+
decoration: InputDecoration(
59+
prefixIcon: widget.prefixIcon,
60+
label: Text(widget.labelText),
61+
suffixIcon: IconButton(
62+
icon: Icon(
63+
_obscureText ? Icons.visibility_off : Icons.visibility,
64+
),
65+
onPressed: () {
66+
setState(() {
67+
_obscureText = !_obscureText;
68+
});
69+
},
70+
),
71+
),
72+
);
73+
}
74+
}

0 commit comments

Comments
 (0)