Reduce nesting of login.dart
This commit is contained in:
parent
3728172844
commit
1cd8ba41ae
|
@ -24,23 +24,17 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
loggingIn = true;
|
loggingIn = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
|
final client = Client("zenith");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final provider =
|
|
||||||
Provider.of<ZenithClientProvider>(context, listen: false);
|
|
||||||
final client = Client("zenith");
|
|
||||||
await client.checkHomeserver(Uri.parse(serverController.text));
|
await client.checkHomeserver(Uri.parse(serverController.text));
|
||||||
final result = await client.login(
|
await client.login(
|
||||||
LoginType.mLoginPassword,
|
LoginType.mLoginPassword,
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
identifier: AuthenticationUserIdentifier(user: usernameController.text),
|
identifier: AuthenticationUserIdentifier(user: usernameController.text),
|
||||||
|
refreshToken: true,
|
||||||
);
|
);
|
||||||
provider.setClient(client);
|
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
prefs.setString("homeserver", serverController.text);
|
|
||||||
prefs.setString("username", usernameController.text);
|
|
||||||
prefs.setString("accessToken", result.accessToken);
|
|
||||||
prefs.setString("refreshToken", result.refreshToken ?? "");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
print(error);
|
print(error);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -60,6 +54,12 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
provider.setClient(client);
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
prefs.setString("homeserver", serverController.text);
|
||||||
|
prefs.setString("username", usernameController.text);
|
||||||
|
prefs.setString("password", passwordController.text);
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user