logout method

Future<void> logout()

Implementation

Future<void> logout() async {
  if (_action != _LoginAction.none) {
    throw StateError("There is already a login or logout action in progress");
  }

  _action = _LoginAction.logout;
  _status = LoginStatus.pending;
  _token = null;
  _error = null;
  notifyListeners();

  try {
    await helper.disconnect();
    _status = LoginStatus.loggedOut;
    _action = _LoginAction.none;
    notifyListeners();
  } catch (e) {
    _error = e;
    _status = LoginStatus.error;
    _action = _LoginAction.none;
    notifyListeners();
    rethrow;
  }
}