Flutter SMS :
Flutter Sms is a short message service as you are all aware of it so let’s get into the tutorial, we will try to send a sms in this part of the tutorial.
Flutter provides the same code base for android & iOS so this tutorial makes you send sms in both android and iOS devices.
We provide a interface for sending sms where we provide recipients numbers and message.
Some times we need to send a sms on completing a certain task from app providing the status of the task as a part of security mostly regarding banking apps we can find these alerts.
Now a days while using UPI payments a sms will be sent to confirm the user bank account details by sending a sms from mobile phone.
Also when you are trying to make a online transaction banks will send a otp to customer device so that if it’s a legitimate transaction user can enter this otp and go ahead with transaction.
Can go through the below tutorial for detailed instructions on flutter sms implementation.
Flutter SMS Video Tutorial:
main.dart :
Initialize with void main()
void main(){ runApp(MyApp()); }
We have considered a default class MyApp extending a stateless widget return Home class.
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Home(), ); } }
We are providing a list of numbers using this list we can send sms to all these numbers at once.
List<String> recipents = ["9876543210", "8765432190"];
Inside a Scaffold declare a app bar and provide title with text widget for flutter sms.
Scaffold( appBar: AppBar(title: Text("Send sms to multiple"),), ),
Provide a button for user to tap on to open default messaging app and provide the message and recipient number’s
RaisedButton( color: Theme.of(context).accentColor, padding: EdgeInsets.symmetric(vertical: 16), ),
Provide text for the button for user to understand
child: Text("Send Sms", style: Theme.of(context).accentTextTheme.button),
Create a method for accepting numbers and message and then create a async method and wait for the result providing await and listen to resilt.
void _sendSMS(String message, List<String> recipents) async { String _result = await sendSMS(message: message, recipients: recipents) .catchError((onError) { print(onError); }); print(_result); }
On pressed the button pass the parameters to the sendSms method
onPressed: () { _sendSMS("This is a test message!", recipents); },
FullCode :
Providing the full code below for sending flutter sms through the app.
import 'package:flutter/material.dart'; import 'package:flutter_sms/flutter_sms.dart'; void main(){ runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Home(), ); } } List<String> recipents = ["9876543210", "8765432190"]; class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Send sms to multiple"),), body: Container( child: Center( child: Padding( padding: const EdgeInsets.all(8.0), child: RaisedButton( color: Theme.of(context).accentColor, padding: EdgeInsets.symmetric(vertical: 16), child: Text("Send Sms", style: Theme.of(context).accentTextTheme.button), onPressed: () { _sendSMS("This is a test message!", recipents); }, ), ), ), ), ); } } void _sendSMS(String message, List<String> recipents) async { String _result = await sendSMS(message: message, recipients: recipents) .catchError((onError) { print(onError); }); print(_result); }
Flutter SMS Output :
This screen depicts the implementation of sending messages flutter sms / mms.
If you have any query’s in this tutorial on flutter sms do let us know in the comment section below. If you like this tutorial do like and share us for more interesting updates.