logout method

Future<void> logout()

logout will try to logout only if We are connected and already logged in

Implementation

Future<void> logout() async {
  try {
    if (isConnected && await _wppAuth.isAuthenticated()) {
      await _wppAuth.logout();

      // Wait for logout state to be reflected
      int attempts = 0;
      while (attempts < 5 && isConnected) {
        if (!(await _wppAuth.isAuthenticated())) break;
        await Future.delayed(const Duration(milliseconds: 500));
        attempts++;
      }
    }
  } catch (e) {
    WhatsappLogger.log(e);
  }
}