Twilio API Send SMS Flutter Example
In this article, we are going to integrate twilio api to send sms from twilio console in flutter application. You can also check out flutter firebase related articles.
In this flutter example, first we create an twilio account to access sms api feature to send a message in flutter application. Using twilio platform, we can also make and receive calls same as sms. After creating twilio account, we get AccountSID and Auth Token which are required in our flutter code to send a message.
Using twilio, we can also send push notifications to users who are registered. We can also verify user phone number with twilio api. Twilio API also supports call tracking if you want. Initially we get $15.00 amount in our twilio account after signup for trial purpose. We can also get trial number from our twilio dashboard to test send and receive sms functionality.
Create Twilio Account



Add required package in pubspec.yaml file
To integrate twilio api with our flutter application to send sms, we must add twilio_flutter package in our pubspec.yaml file.
Initialize Twilio SMS Client
We can initialize TwilioFlutter class with some required information such as Account SID, Auth Token and our twilio number which we get from our twilio dashboard.
@override
void initState() {
myTwilioFlutter = TwilioFlutter(
accountSid: ‘***************************************’,
authToken: ‘*************************************’,
twilioNumber: ‘******************’
);
super.initState();
}
Twilio API Send SMS
We can send a message to verified phone number by using sendSMS method of TwilioFlutter class. We can also customize message text by using messageBody parameter of sendSMS method.
myTwilioFlutter.sendSMS(toNumber: ‘*************’, messageBody: ‘Flutter Twilio SMS Test’);
}
Twilio API Get SMS
We can get sms details from twilio sdk with two ways. First we can get all sms details using getSmsList method of twilio sdk. Second if we have message id of particular sms then we can also get details of that sms separately.
var getSMSData = await myTwilioFlutter.getSmsList();
print(getSMSData);
await myTwilioFlutter.getSMS(‘***************************’);
}
Twilio SMS App UI
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(‘Flutter Twilio SMS Screen’)),
body: Center(
child: ElevatedButton(
style: ElevatedButton.styleFrom(primary: Colors.redAccent, padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15)),
child:Text(‘Send SMS through Twilio’, style: TextStyle( color: Colors.white, fontSize: 25)),
onPressed: sendTwilioSMS,
),
),
);
}

Pingback: Chat App UI Flutter Tutorial with Example - CodingWithDhrumil
Pingback: Quick Action Flutter Example - CodingWithDhrumil