getSmsCode method

Future<SmsCodeResult> getSmsCode({
  1. String matcher = _defaultCodeMatcher,
  2. String? senderPhoneNumber,
  3. bool useUserConsentApi = false,
})

Starts listening to SMS that contains the App signature getAppSignature in the text returns code if it matches with matcher More about SMS Retriever API https://developers.google.com/identity/sms-retriever/overview?hl=en

If useUserConsentApi is true SMS User Consent API will be used https://developers.google.com/identity/sms-retriever/user-consent/overview Which shows confirmations dialog to user to confirm reading the SMS content

Implementation

Future<SmsCodeResult> getSmsCode({
  // used to extract code from SMS
  String matcher = _defaultCodeMatcher,
  // Optional parameter for User Consent API
  String? senderPhoneNumber,
  // if true SMS User Consent API will be used otherwise plugin will use SMS Retriever API
  bool useUserConsentApi = false,
}) async {
  if (senderPhoneNumber != null) {
    assert(
      useUserConsentApi == true,
      'senderPhoneNumber is only supported if useUserConsentApi is true',
    );
  }
  try {
    if (_isAndroid('getSmsCode')) {
      final String? sms = useUserConsentApi
          ? await _channel.invokeMethod(Methods.startSmsUserConsent, {
              'senderPhoneNumber': senderPhoneNumber,
            })
          : await _channel.invokeMethod(Methods.startSmsRetriever);
      return SmsCodeResult.fromSms(sms, matcher);
    }
  } catch (error) {
    debugPrint('Pinput/SmartAuth: getSmsCode failed: $error');
    return SmsCodeResult.fromSms(null, matcher);
  }

  return SmsCodeResult.fromSms(null, matcher);
}