login static method

Future<User?> login(
  1. String uid,
  2. String authKey,
  3. {required dynamic onSuccess(
    1. User user
    )?,
  4. required dynamic onError(
    1. CometChatException excep
    )?}
)

Use this function only for testing purpose. For production, use loginWithAuthToken

Implementation

static Future<User?> login(String uid, String authKey, {required Function(User user)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('loginWithApiKey', {
      'uid': uid,
      'apiKey': authKey,
    });
    final User res = User.fromMap(result);
    if(onSuccess != null) onSuccess(res);
    return res;
  } on PlatformException catch (platformException) {
    if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
  } catch (e) {
    debugPrint("Error: $e");
    if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
  }
  return null;
}