updatePhone static method

Future<AuthResult> updatePhone(
  1. String phone,
  2. String phoneCode, [
  3. String? oldPhone,
  4. String? oldPhoneCode,
  5. String? phoneCountryCode,
  6. String? oldPhoneCountryCode,
])

2230 same phone number 1320004 phone already bind

Implementation

static Future<AuthResult> updatePhone(String phone, String phoneCode,
    [String? oldPhone,
    String? oldPhoneCode,
    String? phoneCountryCode,
    String? oldPhoneCountryCode]) async {
  Map map = {};
  map.putIfAbsent('phone', () => phone);
  map.putIfAbsent('phoneCode', () => phoneCode);
  if (oldPhone != null && oldPhoneCode != null) {
    map.putIfAbsent('oldPhone', () => oldPhone);
    map.putIfAbsent('oldPhoneCode', () => oldPhoneCode);
  }
  if (phoneCountryCode != null) {
    map.putIfAbsent('phoneCountryCode', () => phoneCountryCode);
  }
  if (oldPhoneCountryCode != null) {
    map.putIfAbsent('oldPhoneCountryCode', () => oldPhoneCountryCode);
  }
  final Result result =
      await post('/api/v2/users/phone/update', jsonEncode(map));
  AuthResult authResult = AuthResult(result);
  if (result.code == 200) {
    authResult.user = await createUser(result);
  }
  return authResult;
}