mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 23:09:35 +01:00
Fix login loading dialog
This commit is contained in:
parent
ee9fc0ccd1
commit
2c047d9b21
@ -19,6 +19,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
String usernameError;
|
String usernameError;
|
||||||
String passwordError;
|
String passwordError;
|
||||||
String serverError;
|
String serverError;
|
||||||
|
bool loading = false;
|
||||||
|
|
||||||
void login(BuildContext context) async {
|
void login(BuildContext context) async {
|
||||||
MatrixState matrix = Matrix.of(context);
|
MatrixState matrix = Matrix.of(context);
|
||||||
@ -46,28 +47,28 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
matrix.showLoadingDialog(context);
|
setState(() => loading = true);
|
||||||
if (!await matrix.client.checkServer(homeserver)) {
|
if (!await matrix.client.checkServer(homeserver)) {
|
||||||
setState(() => serverError = "Homeserver is not compatible.");
|
setState(() => serverError = "Homeserver is not compatible.");
|
||||||
|
|
||||||
return matrix.hideLoadingDialog();
|
return setState(() => loading = false);
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
setState(() => serverError = "Connection attempt failed!");
|
setState(() => serverError = "Connection attempt failed!");
|
||||||
return matrix.hideLoadingDialog();
|
return setState(() => loading = false);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await matrix.client
|
await matrix.client
|
||||||
.login(usernameController.text, passwordController.text);
|
.login(usernameController.text, passwordController.text);
|
||||||
} on MatrixException catch (exception) {
|
} on MatrixException catch (exception) {
|
||||||
setState(() => passwordError = exception.errorMessage);
|
setState(() => passwordError = exception.errorMessage);
|
||||||
return matrix.hideLoadingDialog();
|
return setState(() => loading = false);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
setState(() => passwordError = exception.toString());
|
setState(() => passwordError = exception.toString());
|
||||||
return matrix.hideLoadingDialog();
|
return setState(() => loading = false);
|
||||||
}
|
}
|
||||||
await Matrix.of(context).saveAccount();
|
await Matrix.of(context).saveAccount();
|
||||||
matrix.hideLoadingDialog();
|
setState(() => loading = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -130,12 +131,14 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: RawMaterialButton(
|
child: RawMaterialButton(
|
||||||
onPressed: () => login(context),
|
onPressed: () => loading ? null : login(context),
|
||||||
splashColor: Colors.grey,
|
splashColor: Colors.grey,
|
||||||
child: Text(
|
child: loading
|
||||||
"Login",
|
? CircularProgressIndicator()
|
||||||
style: TextStyle(color: Colors.white, fontSize: 20.0),
|
: Text(
|
||||||
),
|
"Login",
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 20.0),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user