SmsUserConsent constructor

SmsUserConsent({
  1. Function? phoneNumberListener,
  2. Function? smsListener,
})

SmsUserConsent plugin works only on Android, hence make sure to check the platform is Android.

Optional phone number listener, called when user selects a phone number (returns null if user selects none of the above or taps out of the phone number selection dialog).

Optional sms listener, called when sms is retrieved if it meets these criteria:

  • The message contains a 4-10 character alphanumeric string with at least one number.
  • The message was sent by a phone number that's not in the user's contacts.
  • If you specified the sender's phone number, the message was sent by that number.

Implementation

SmsUserConsent({Function? phoneNumberListener, Function? smsListener}) {
  _phoneNumberListener = phoneNumberListener;
  _smsListener = smsListener;
  _channel.setMethodCallHandler((call) async {
    switch (call.method) {
      case 'selectedPhoneNumber':
        _selectedPhoneNumber = call.arguments;
        _phoneNumberListener!();
        break;
      case 'receivedSms':
        _receivedSms = call.arguments;
        _smsListener!();
        break;
      default:
    }
  });
}