sendSms method
Send an SMS
Take a message in argument + 2 functions that will be called on success or on error
This function will not set automatically thread id, you have to do it
Implementation
Future<SmsMessage?> sendSms(SmsMessage msg, {SimCard? simCard}) async {
if (msg.address == null || msg.body == null) {
if (msg.address == null) {
throw ("no given address");
} else if (msg.body == null) {
throw ("no given body");
}
return null;
}
msg.state = SmsMessageState.Sending;
Map map = msg.toMap;
_sentMessages.putIfAbsent(_sentId, () => msg);
map['sentId'] = _sentId;
if (simCard != null) {
map['subId'] = simCard.slot;
}
_sentId += 1;
if (simCard != null) {
map['simCard'] = simCard.imei;
}
if (!kIsWeb && Platform.isIOS) {
final mapData = <dynamic, dynamic>{
"message": map['body'],
"recipients": [map['address']],
};
await _channel.invokeMethod("sendSMS", mapData);
msg.date = DateTime.now();
} else {
await _channel.invokeMethod("sendSMS", map);
msg.date = DateTime.now();
}
return msg;
}