Files
flutter/lib/widgets/auth/password_field.dart
Roland Geider ece38a39d2 Refactor login screen
The api token toggle is now only visible when showing a custom server, since at
the moment this is the only time when such an auth method makes sense (plus it
keeps the rest of the UI cleaner). The different fields in the screen have been
moved to individual files, to make the structure clearer.
2025-04-30 22:50:55 +02:00

50 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
class PasswordField extends StatefulWidget {
final TextEditingController controller;
final Function(String?) onSaved;
const PasswordField({
required this.controller,
required this.onSaved,
super.key,
});
@override
_PasswordFieldState createState() => _PasswordFieldState();
}
class _PasswordFieldState extends State<PasswordField> {
bool isObscure = true;
@override
Widget build(BuildContext context) {
return TextFormField(
key: const Key('inputPassword'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).password,
prefixIcon: const Icon(Icons.password),
suffixIcon: IconButton(
icon: Icon(isObscure ? Icons.visibility_off : Icons.visibility),
onPressed: () {
setState(() {
isObscure = !isObscure;
});
},
),
),
obscureText: isObscure,
controller: widget.controller,
textInputAction: TextInputAction.next,
validator: (value) {
if (value == null || value.isEmpty || value.length < 8) {
return AppLocalizations.of(context).passwordTooShort;
}
return null;
},
onSaved: widget.onSaved,
);
}
}