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.
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.
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.