sendSms method

Future<void> sendSms({
  1. required String to,
  2. required String message,
  3. SmsSendStatusListener? statusListener,
  4. bool isMultipart = false,
})

Send an SMS directly from your application. Uses Android's SmsManager to send SMS.

Requires SEND_SMS permission.

Parameters:

  • to : Address to send the SMS to.
  • message : Message to be sent. If message body is longer than standard SMS length limits set appropriate value for isMultipart
  • statusListener (optional) : Listen to the status of the sent SMS. Values can be one of SmsStatus
  • isMultipart (optional) : If message body is longer than standard SMS limit of 160 characters, set this flag to send the SMS in multiple parts.

Implementation

Future<void> sendSms({
  required String to,
  required String message,
  SmsSendStatusListener? statusListener,
  bool isMultipart = false,
}) async {
  assert(_platform.isAndroid == true, "Can only be called on Android.");
  bool listenStatus = false;
  if (statusListener != null) {
    _statusListener = statusListener;
    listenStatus = true;
  }
  final Map<String, dynamic> args = {
    "address": to,
    "message_body": message,
    "listen_status": listenStatus
  };
  final String method = isMultipart ? SEND_MULTIPART_SMS : SEND_SMS;
  await _foregroundChannel.invokeMethod(method, args);
}