MissingPluginException(No implementation found for method send on channel sendSms) in Flutter

Viewed 19

I doing custom app send sms auto for users

I used many lib but it not working and my code bellow

Future<void> sendSMS(phoneNumber, message) async {
const platform = MethodChannel('sendSms');
try {
  final String result = await platform.invokeMethod('send', <String, dynamic>{
   "phone": phoneNumber,
   "msg": message
 });
   print(result);
 } on PlatformException catch (e) {
  print(e.toString());
 }
}

but when running my app throw exception with error:

 MissingPluginException(No implementation found for method send on channel sendSms)

Thanks for any suport

1 Answers

Unless you are creating a plugin yourself, it's unlikely you need to use the invokeMethod call directly. If you use a plugin (as I expect you are) then the plugin you use will provide you with regular Dart functions or classes that you can use to do what you want the plugin to do (for example, send an SMS).

For example, if you are using the flutter_sms plugin, then per that plugin's documentation you send an SMS using

String _result = await sendSMS(message: message, recipients: recipents)
        .catchError((onError) {
      print(onError);
    });

As you can see, you don't use invokeMethodChannel, because the plugin does that for you 'under the hood'.

Related