2026-03-13 14:10:13 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
2026-03-27 14:05:03 +08:00
|
|
|
import '../../../../core/l10n/l10n.dart';
|
2026-03-13 14:10:13 +08:00
|
|
|
import 'auth_field.dart';
|
|
|
|
|
|
|
|
|
|
class PasswordField extends StatefulWidget {
|
|
|
|
|
const PasswordField({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.controller,
|
2026-03-19 18:42:05 +08:00
|
|
|
this.label,
|
2026-03-13 14:10:13 +08:00
|
|
|
required this.hint,
|
|
|
|
|
this.onChanged,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final TextEditingController controller;
|
2026-03-19 18:42:05 +08:00
|
|
|
final String? label;
|
2026-03-13 14:10:13 +08:00
|
|
|
final String hint;
|
|
|
|
|
final ValueChanged<String>? onChanged;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<PasswordField> createState() => _PasswordFieldState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PasswordFieldState extends State<PasswordField> {
|
|
|
|
|
bool _obscured = true;
|
|
|
|
|
|
|
|
|
|
void _toggleVisibility() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_obscured = !_obscured;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-03-27 19:07:39 +08:00
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
|
|
2026-03-13 14:10:13 +08:00
|
|
|
return AuthField(
|
|
|
|
|
label: widget.label,
|
|
|
|
|
hint: widget.hint,
|
|
|
|
|
controller: widget.controller,
|
|
|
|
|
obscureText: _obscured,
|
|
|
|
|
onChanged: widget.onChanged,
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
onPressed: _toggleVisibility,
|
2026-03-27 14:05:03 +08:00
|
|
|
tooltip: _obscured
|
|
|
|
|
? context.l10n.authShowPassword
|
|
|
|
|
: context.l10n.authHidePassword,
|
2026-03-13 14:10:13 +08:00
|
|
|
icon: Icon(
|
|
|
|
|
_obscured ? Icons.visibility_off_rounded : Icons.visibility_rounded,
|
2026-03-27 19:07:39 +08:00
|
|
|
color: colorScheme.onSurfaceVariant,
|
2026-03-13 14:10:13 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|