I am trying to create a flutter application that sends SMS to relatives of an elderly person if he has not consumed his medicine on time. I was planning on using Twilio but there is not enough documentation and resources for me to implement it. Please help
Asked
Active
Viewed 995 times
2 Answers
1
Have you checked out this Dart helper library for Twilio?
- Add a dependency to
twilio_dart
to your pubspec.yaml - Run
pub get
- Get a key and authentication code from your Twilio console. The account is limited but free.
Now you can make a new Twilio object with your account details like so:
import 'package:twilio_dart/twilio.dart';
var key = "your_twilio_key";
var authToken = "your_auth_token";
var version = "2010-04-01";
//create a new twilio object
Twilio twilio = new Twilio(key, authToken, version);
To send a SMS with this, add
var from = "your_twilio_phone";
var to = "your_mobile_number";
var body = "Look ma! Dart can now send SMS's in under 15 lines";
and check out the repo for more!

Dharman
- 30,962
- 25
- 85
- 135

lizziepika
- 3,231
- 1
- 14
- 23
-
I Already tried that package. It generates this error. The current Dart SDK version is 2.7.0. Because *******_app depends on twilio_dart any which requires SDK version >=0.8.10+6 <2.0.0, version solving failed. pub get failed (1; Because elderly_app depends on twilio_dart any which requires SDK version >=0.8.10+6 <2.0.0, version solving failed.) – Adarsh Balu Mar 05 '20 at 17:53
-
@AdarshBalu try to update your app's pubspec.yaml to `environment: sdk: ">=2.1.0 <3.0.0"` – Alex Baban Mar 06 '20 at 01:28
-
@AlexBaban It's already updated. The issue is with that package. – Adarsh Balu Mar 06 '20 at 09:47
-
@AdarshBalu can you update your question and add the code you have in pubspec.yaml for your app and also pubspec.yaml for twilio_dart? I'm trying to figure out from where that `>=0.8.10+6 <2.0.0` is coming. At GitHub twilio_dart depends of `sdk: '>=2.0.0-dev.68.0 <3.0.0'`. – Alex Baban Mar 06 '20 at 11:29
0
I found another way to do this using just the Http package
import 'package:http/http.dart' as http;
import 'dart:convert';
void sendSMS() async {
var cred =
'ACCOUNT_SID:AUTH_TOKEN';
var bytes = utf8.encode(cred);
var base64Str = base64.encode(bytes);
var url =
'https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Messages.json';
var response = await http.post(url, headers: {
'Authorization': 'Basic ${base64Str}'
}, body: {
'From': '+xxxxxxxx', //twilio number
'To': '+15558675310',
'Body': 'Hello world!'
});
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}
Using this function we can send SMS from a Twilio Number. Correct me if I'm wrong. Cheers.

Adarsh Balu
- 322
- 2
- 12