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;
|
||||
});
|
||||
|
||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
|
||||
try {
|
||||
final provider =
|
||||
Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
await client.checkHomeserver(Uri.parse(serverController.text));
|
||||
final result = await client.login(
|
||||
await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
password: passwordController.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) {
|
||||
print(error);
|
||||
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;
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
|
|
Loading…
Reference in New Issue
Block a user