forked from qwertypool/flutter-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword-toggle.dart
35 lines (35 loc) · 921 Bytes
/
password-toggle.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import 'package:flutter/material.dart';
class LoginForm extends StatefulWidget {
@override
_LoginFormState createState() => _LoginFormState();
}
class _LoginFormState extends State<LoginForm> {
bool _isHidden = true;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).secondaryHeaderColor,
body: Center(
child: TextField(
obscureText: _isHidden,
decoration: InputDecoration(
hintText: 'Password',
suffix: InkWell(
onTap: _togglePasswordView,
child: Icon(
_isHidden
? Icons.visibility
: Icons.visibility_off,
),
),
),
),
),
);
}
void _togglePasswordView() {
setState(() {
_isHidden = !_isHidden;
});
}
}