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 password = useTextEditingController();
|
||||||
|
|
||||||
final inputError = useState<String?>(null);
|
final inputError = useState<String?>(null);
|
||||||
|
final formKey = useRef(GlobalKey<FormState>());
|
||||||
|
|
||||||
Future<void> tryLogin() async {
|
Future<void> tryLogin() async {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (formKey.value.currentState?.validate() != true) return;
|
||||||
|
|
||||||
final error = await client.login(
|
final error = await client.login(
|
||||||
.new(
|
.new(
|
||||||
username: username.text,
|
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(
|
return Scaffold(
|
||||||
appBar: Appbar(
|
appBar: Appbar(
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
|
|
@ -50,30 +56,35 @@ class LoginPage extends HookConsumerWidget {
|
||||||
),
|
),
|
||||||
body: AlertDialog(
|
body: AlertDialog(
|
||||||
title: Text("Login to ${homeserver.host}"),
|
title: Text("Login to ${homeserver.host}"),
|
||||||
content: Column(
|
content: Form(
|
||||||
mainAxisSize: .min,
|
key: formKey.value,
|
||||||
crossAxisAlignment: .start,
|
child: Column(
|
||||||
children: [
|
mainAxisSize: .min,
|
||||||
TextField(
|
crossAxisAlignment: .start,
|
||||||
autofocus: true,
|
children: [
|
||||||
textInputAction: .next,
|
TextFormField(
|
||||||
decoration: .new(label: Text("Username")),
|
autofocus: true,
|
||||||
controller: username,
|
textInputAction: .next,
|
||||||
),
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
SizedBox(height: 12),
|
validator: requiredValidator,
|
||||||
TextField(
|
decoration: .new(label: Text("Username")),
|
||||||
textInputAction: .done,
|
controller: username,
|
||||||
onSubmitted: (_) => tryLogin(),
|
|
||||||
selectAllOnFocus: true,
|
|
||||||
decoration: .new(
|
|
||||||
label: Text("Password"),
|
|
||||||
errorText: inputError.value,
|
|
||||||
errorMaxLines: 5,
|
|
||||||
),
|
),
|
||||||
controller: password,
|
SizedBox(height: 12),
|
||||||
obscureText: true,
|
TextFormField(
|
||||||
),
|
textInputAction: .done,
|
||||||
],
|
decoration: .new(
|
||||||
|
label: Text("Password"),
|
||||||
|
errorText: inputError.value,
|
||||||
|
errorMaxLines: 5,
|
||||||
|
),
|
||||||
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
|
validator: requiredValidator,
|
||||||
|
controller: password,
|
||||||
|
obscureText: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue