switchTo method
- UserId id
Switches to the account with the given id
.
Implementation
Future<void> switchTo(UserId id) async {
try {
// TODO: This is a hack that should be removed, as whenever the account is
// changed, the [HomeView] and its dependencies must be rebuilt,
// which may take some unidentifiable amount of time as of now.
router.nowhere();
final bool succeeded = await _authService.switchAccount(id);
if (succeeded) {
await Future.delayed(500.milliseconds);
router.tab = HomeTab.chats;
router.home();
} else {
await Future.delayed(500.milliseconds);
router.home();
await Future.delayed(500.milliseconds);
MessagePopup.error('err_account_unavailable'.l10n);
}
} catch (e) {
await Future.delayed(500.milliseconds);
router.home();
await Future.delayed(500.milliseconds);
MessagePopup.error(e);
}
}