updatePhone static method

Future<AuthResult> updatePhone(
  1. String newPhoneNumber,
  2. String newPhonePassCode, [
  3. String? oldPhoneNumber,
  4. String? oldPhonePassCode,
  5. String? newPhoneCountryCode,
  6. String? oldPhoneCountryCode,
])

2230 same phone number 1320004 phone already bind

Implementation

static Future<AuthResult> updatePhone(
    String newPhoneNumber, String newPhonePassCode,
    [String? oldPhoneNumber,
    String? oldPhonePassCode,
    String? newPhoneCountryCode,
    String? oldPhoneCountryCode]) async {
  Map map = {};
  map.putIfAbsent('newPhoneNumber', () => newPhoneNumber);
  map.putIfAbsent('newPhonePassCode', () => newPhonePassCode);
  if (oldPhoneNumber != null && oldPhonePassCode != null) {
    map.putIfAbsent('oldPhoneNumber', () => oldPhoneNumber);
    map.putIfAbsent('oldPhonePassCode', () => oldPhonePassCode);
  }
  if (newPhoneCountryCode != null) {
    map.putIfAbsent('newPhoneCountryCode', () => newPhoneCountryCode);
  }
  if (oldPhoneCountryCode != null) {
    map.putIfAbsent('oldPhoneCountryCode', () => oldPhoneCountryCode);
  }
  var body = {'verifyMethod': 'PHONE_PASSCODE', 'phonePassCodePayload': map};
  final Result tokenResult =
      await post('/api/v3/verify-update-phone-request', jsonEncode(body));
  if (tokenResult.statusCode == 200) {
    final Result result = await post('/api/v3/update-phone',
        jsonEncode(tokenResult.data['updatePhoneToken']));
    AuthResult authResult = AuthResult(result);
    return authResult;
  } else {
    return AuthResult(tokenResult);
  }
}