Fix login loading dialog

This commit is contained in:
Christian Pauly 2020-01-04 09:16:29 +01:00
parent ee9fc0ccd1
commit 2c047d9b21

View file

@ -19,6 +19,7 @@ class _LoginPageState extends State<LoginPage> {
String usernameError;
String passwordError;
String serverError;
bool loading = false;
void login(BuildContext context) async {
MatrixState matrix = Matrix.of(context);
@ -46,28 +47,28 @@ class _LoginPageState extends State<LoginPage> {
}
try {
matrix.showLoadingDialog(context);
setState(() => loading = true);
if (!await matrix.client.checkServer(homeserver)) {
setState(() => serverError = "Homeserver is not compatible.");
return matrix.hideLoadingDialog();
return setState(() => loading = false);
}
} catch (exception) {
setState(() => serverError = "Connection attempt failed!");
return matrix.hideLoadingDialog();
return setState(() => loading = false);
}
try {
await matrix.client
.login(usernameController.text, passwordController.text);
} on MatrixException catch (exception) {
setState(() => passwordError = exception.errorMessage);
return matrix.hideLoadingDialog();
return setState(() => loading = false);
} catch (exception) {
setState(() => passwordError = exception.toString());
return matrix.hideLoadingDialog();
return setState(() => loading = false);
}
await Matrix.of(context).saveAccount();
matrix.hideLoadingDialog();
setState(() => loading = false);
}
@override
@ -130,12 +131,14 @@ class _LoginPageState extends State<LoginPage> {
),
),
child: RawMaterialButton(
onPressed: () => login(context),
onPressed: () => loading ? null : login(context),
splashColor: Colors.grey,
child: Text(
"Login",
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
child: loading
? CircularProgressIndicator()
: Text(
"Login",
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
),
),
),