Skip to content

Commit e87fcba

Browse files
committed
login: Add button to show/hide password
Fixes-partly: zulip#35
1 parent cdfa189 commit e87fcba

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/widgets/login.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
9999
final GlobalKey<FormFieldState<String>> _emailKey = GlobalKey();
100100
final GlobalKey<FormFieldState<String>> _passwordKey = GlobalKey();
101101

102+
bool _obscurePassword = true;
103+
void _handlePasswordVisibilityPress() {
104+
setState(() {
105+
_obscurePassword = !_obscurePassword;
106+
});
107+
}
108+
102109
Future<int> _getUserId(FetchApiKeyResult fetchApiKeyResult) async {
103110
final FetchApiKeyResult(:email, :apiKey) = fetchApiKeyResult;
104111
final auth = Auth(
@@ -177,10 +184,14 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
177184
const SizedBox(height: 8),
178185
TextFormField(
179186
key: _passwordKey,
180-
obscureText: true,
187+
obscureText: _obscurePassword,
181188
keyboardType: TextInputType.visiblePassword,
182-
decoration: const InputDecoration(
183-
labelText: 'Password')),
189+
decoration: InputDecoration(
190+
labelText: 'Password',
191+
suffixIcon: Semantics(label: 'Hide password', toggled: _obscurePassword,
192+
child: IconButton(
193+
onPressed: _handlePasswordVisibilityPress,
194+
icon: _obscurePassword ? const Icon(Icons.visibility_off) : const Icon(Icons.visibility))))),
184195
const SizedBox(height: 8),
185196
ElevatedButton(
186197
onPressed: _submit,

0 commit comments

Comments
 (0)