Add loader for logging in
This commit is contained in:
parent
302f46804e
commit
5c4526f1fc
102
lib/login.dart
102
lib/login.dart
|
@ -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(() {
|
||||||
await provider.initialize(serverController.text, usernameController.text,
|
loggingIn = true;
|
||||||
passwordController.text);
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
final provider =
|
||||||
|
Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
|
await provider.initialize(serverController.text, usernameController.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,40 +65,47 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Consumer<ZenithClientProvider>(
|
||||||
appBar: AppBar(
|
builder: (context, provider, child) => Scaffold(
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
appBar: AppBar(
|
||||||
title: const Text("Login"),
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
),
|
title: const Text("Login"),
|
||||||
body: Padding(
|
),
|
||||||
padding: const EdgeInsets.all(16.0),
|
body: Padding(
|
||||||
child: Center(
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Center(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
child: Column(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
TextFormField(
|
children: [
|
||||||
controller: serverController,
|
TextFormField(
|
||||||
decoration: const InputDecoration(
|
controller: serverController,
|
||||||
labelText: 'Server', hintText: 'https://matrix.org'),
|
decoration: const InputDecoration(
|
||||||
),
|
labelText: 'Server', hintText: 'https://matrix.org'),
|
||||||
TextFormField(
|
),
|
||||||
controller: usernameController,
|
TextFormField(
|
||||||
decoration: const InputDecoration(
|
controller: usernameController,
|
||||||
labelText: 'Username', hintText: 'john'),
|
decoration: const InputDecoration(
|
||||||
),
|
labelText: 'Username', hintText: 'john'),
|
||||||
TextFormField(
|
),
|
||||||
controller: passwordController,
|
TextFormField(
|
||||||
decoration: const InputDecoration(labelText: 'Password'),
|
controller: passwordController,
|
||||||
obscureText: true,
|
decoration: const InputDecoration(labelText: 'Password'),
|
||||||
),
|
obscureText: true,
|
||||||
],
|
onFieldSubmitted: (value) => connectMatrix(),
|
||||||
|
),
|
||||||
|
Text(failedMessage,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
floatingActionButton: loggingIn
|
||||||
floatingActionButton: FloatingActionButton(
|
? const CircularProgressIndicator()
|
||||||
onPressed: connectMatrix,
|
: FloatingActionButton(
|
||||||
tooltip: 'Log in',
|
onPressed: connectMatrix,
|
||||||
child: const Icon(Icons.login),
|
tooltip: 'Log in',
|
||||||
|
child: const Icon(Icons.login),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user