anonymousLogin method Null safety

void anonymousLogin(
  1. String appKey,
  2. String subDomain
)

Implementation

static void anonymousLogin(String appKey, String subDomain) async {
  /// sp初始化
  await SpUtil.getInstance();
  // 首先检测是否是第一次,如果是第一此启动
  String? username = SpUtil.getString(BytedeskConstants.username);
  String? unionid = SpUtil.getString(BytedeskConstants.unionid);
  if (username!.isEmpty && unionid!.isEmpty) {
    // 第一此启动, 则调用注册接口,否则调用登录接口
    User user = await BytedeskUserHttpApi().registerAnonymous(subDomain);
    visitorLogin(user.username!, appKey, subDomain);
  } else if (username.isNotEmpty) {
    // 用户名登录,非微信登录
    visitorLogin(username, appKey, subDomain);
  } else if (unionid!.isNotEmpty) {
    // 微信登录
    unionidOAuth(unionid);
  } else {
    // 验证码登录其他账号,非当前匿名登录账户
    otherOAuth();
  }
}