make login page use a Form
This commit is contained in:
parent
a8c7753c20
commit
a98afcff3d
1 changed files with 34 additions and 23 deletions
|
|
@ -17,11 +17,14 @@ class LoginPage extends HookConsumerWidget {
|
|||
final password = useTextEditingController();
|
||||
|
||||
final inputError = useState<String?>(null);
|
||||
final formKey = useRef(GlobalKey<FormState>());
|
||||
|
||||
Future<void> tryLogin() async {
|
||||
isLoading.value = true;
|
||||
|
||||
try {
|
||||
if (formKey.value.currentState?.validate() != true) return;
|
||||
|
||||
final error = await client.login(
|
||||
.new(
|
||||
username: username.text,
|
||||
|
|
@ -41,6 +44,9 @@ class LoginPage extends HookConsumerWidget {
|
|||
}
|
||||
}
|
||||
|
||||
String? requiredValidator(String? value) =>
|
||||
value == null || value.isEmpty ? "This field is required" : null;
|
||||
|
||||
return Scaffold(
|
||||
appBar: Appbar(
|
||||
leading: IconButton(
|
||||
|
|
@ -50,30 +56,35 @@ class LoginPage extends HookConsumerWidget {
|
|||
),
|
||||
body: AlertDialog(
|
||||
title: Text("Login to ${homeserver.host}"),
|
||||
content: Column(
|
||||
mainAxisSize: .min,
|
||||
crossAxisAlignment: .start,
|
||||
children: [
|
||||
TextField(
|
||||
autofocus: true,
|
||||
textInputAction: .next,
|
||||
decoration: .new(label: Text("Username")),
|
||||
controller: username,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
TextField(
|
||||
textInputAction: .done,
|
||||
onSubmitted: (_) => tryLogin(),
|
||||
selectAllOnFocus: true,
|
||||
decoration: .new(
|
||||
label: Text("Password"),
|
||||
errorText: inputError.value,
|
||||
errorMaxLines: 5,
|
||||
content: Form(
|
||||
key: formKey.value,
|
||||
child: Column(
|
||||
mainAxisSize: .min,
|
||||
crossAxisAlignment: .start,
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
textInputAction: .next,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: requiredValidator,
|
||||
decoration: .new(label: Text("Username")),
|
||||
controller: username,
|
||||
),
|
||||
controller: password,
|
||||
obscureText: true,
|
||||
),
|
||||
],
|
||||
SizedBox(height: 12),
|
||||
TextFormField(
|
||||
textInputAction: .done,
|
||||
decoration: .new(
|
||||
label: Text("Password"),
|
||||
errorText: inputError.value,
|
||||
errorMaxLines: 5,
|
||||
),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: requiredValidator,
|
||||
controller: password,
|
||||
obscureText: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue