verifyPhoneNumber method

Future<bool> verifyPhoneNumber(
  1. String region,
  2. String phoneNumber
)

verifyPhoneNumber verifies if the phoneNumber passed matches the phone number of the currently signed in user in the snapchat app. Always returns false on Android. A two character region code and phoneNumber must be passed

region is a two (2) character region code eg. 'US'

phoneNumber is a ten (10) character String containing an area code and phone number

Throws a PlatformException if the phone number is incorrectly formatted, if the user cancelled the action or if something else went wrong

Implementation

Future<bool> verifyPhoneNumber(String region, String phoneNumber) async {
  try {
    List<dynamic> resVerify =
        await _channel.invokeMethod('verifyNumber', <String, String>{
      'phoneNumber': phoneNumber,
      'region': region.toString(),
    }) as List<dynamic>;

    String phoneId = resVerify[0];
    String verifyId = resVerify[1];

    http.Response res = await http.post(
      Uri(
        scheme: 'https',
        host: 'api.snapkit.com',
        path: '/v1/phoneverify/verify_result',
      ),
      body: {
        'phone_number_id': phoneId,
        'phone_number_verify_id': verifyId,
        'phone_number': phoneNumber,
        'region': region.toString(),
      },
    );

    if (res.statusCode == 200) {
      dynamic json = jsonDecode(res.body);
      return (json['verified'] as bool?) ?? false;
    } else {
      return false;
    }
  } on PlatformException catch (e) {
    throw e;
  }
}