initWithUsernameAndNicknameAndAvatar method Null safety

void initWithUsernameAndNicknameAndAvatar(
  1. String username,
  2. String nickname,
  3. String avatar,
  4. String appKey,
  5. String subDomain
)

Implementation

static void initWithUsernameAndNicknameAndAvatar(String username,
    String nickname, String avatar, String appKey, String subDomain) async {
  // anonymousLogin(appKey, subDomain);
  /// sp初始化
  await SpUtil.getInstance();
  // 首先检测是否是第一次,如果是第一此启动
  String? spusername = SpUtil.getString(BytedeskConstants.username);
  if (spusername!.isEmpty) {
    // 第一此启动, 则调用注册接口,否则调用登录接口
    String password = username;
    await BytedeskUserHttpApi()
        .registerUser(username, nickname, password, avatar, subDomain);
    username = username + "@" + subDomain;
    userLogin(username, password, appKey, subDomain);
  } else if (spusername == username) {
    // 同一个账号,直接登录
    String password = username;
    username = username + "@" + subDomain;
    userLogin(username, password, appKey, subDomain);
  } else {
    // TODO: 切换新用户登录, 首先判断用户是否已经存在,如不存在着注册;如存在则直接登录
    // String password = username;
    // username = username + "@" + subDomain;
    // userLogin(username, password, appKey, subDomain);
  }
}