logout method

void logout({
  1. dynamic onSuccess() = _defaultOnLogout,
  2. dynamic onError(
    1. LogoutError error
    ) = _defaultOnLogoutError,
  3. LogoutParams params = const LogoutParams._(),
})

Logs out the current user.

Calls onSuccess after logout. In case any error was encountered during logout calls onError instead.

params are added for backwards compatibility and for now are always empty.

Usage example:

final vkid = await VKID.getInstance();
vkid.logout(
.   onSuccess: () => print("success"),
    onError: (error) => print(error),
);

Implementation

void logout({
  Function() onSuccess = _defaultOnLogout,
  Function(LogoutError error) onError = _defaultOnLogoutError,
  LogoutParams params = const LogoutParams._(),
}) async {
  try {
    await _platform.invokeMethod("logout", []);
    onSuccess();
  } on PlatformException catch (e) {
    onError(e.code == "expired"
        ? const LogoutAccessTokenExpiredError._()
        : LogoutOtherError._(e.message ?? ""));
  } catch (e) {
    onError(const LogoutOtherError._("unknown error"));
  }
}