Add loader for logging in
This commit is contained in:
parent
302f46804e
commit
5c4526f1fc
|
@ -15,11 +15,36 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
final serverController = TextEditingController();
|
final serverController = TextEditingController();
|
||||||
final usernameController = TextEditingController();
|
final usernameController = TextEditingController();
|
||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
|
bool loggingIn = false;
|
||||||
|
String failedMessage = '';
|
||||||
|
|
||||||
void connectMatrix() async {
|
void connectMatrix() async {
|
||||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
setState(() {
|
||||||
|
loggingIn = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
final provider =
|
||||||
|
Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
await provider.initialize(serverController.text, usernameController.text,
|
await provider.initialize(serverController.text, usernameController.text,
|
||||||
passwordController.text);
|
passwordController.text);
|
||||||
|
} catch (error) {
|
||||||
|
print("Error signing in $error");
|
||||||
|
setState(() {
|
||||||
|
failedMessage = error.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
Future.delayed(const Duration(seconds: 10), () {
|
||||||
|
setState(() {
|
||||||
|
failedMessage = '';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
loggingIn = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString("homeserver", serverController.text);
|
prefs.setString("homeserver", serverController.text);
|
||||||
|
@ -40,7 +65,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Consumer<ZenithClientProvider>(
|
||||||
|
builder: (context, provider, child) => Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
title: const Text("Login"),
|
title: const Text("Login"),
|
||||||
|
@ -65,16 +91,22 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
decoration: const InputDecoration(labelText: 'Password'),
|
decoration: const InputDecoration(labelText: 'Password'),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
|
onFieldSubmitted: (value) => connectMatrix(),
|
||||||
),
|
),
|
||||||
|
Text(failedMessage,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: loggingIn
|
||||||
|
? const CircularProgressIndicator()
|
||||||
|
: FloatingActionButton(
|
||||||
onPressed: connectMatrix,
|
onPressed: connectMatrix,
|
||||||
tooltip: 'Log in',
|
tooltip: 'Log in',
|
||||||
child: const Icon(Icons.login),
|
child: const Icon(Icons.login),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user