sms 0.1.0 copy "sms: ^0.1.0" to clipboard
sms: ^0.1.0 copied to clipboard

outdatedDart 1 only

SMS library

Flutter SMS #

This is an SMS library for flutter.

It only support Android for now (I can't do it for iOS because I don't own Mac).

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Installation and Usage #

Once you're familiar with Flutter you may install this package adding sms (0.1.0 or higher) to the dependencies list of the pubspec.yaml file as follow:

dependencies:
  flutter:
    sdk: flutter

  sms: ^0.1.0

Then run the command flutter packages get on the console.

Querying SMS messages #

Add the import statement for sms and create an instance of the SmsQuery class:

import 'package:sms/sms.dart';

void main() {
  SmsQuery query = new SmsQuery();
}

Getting all SMS messages #

List<SmsMessage> messages = await query.getAllSms;

Note: the use of await keyword means that getAllSms is resolved asynchronously and a Future is retorned.

Filtering SMS messages #

The method querySms from the SmsQuery class returns a list of sms depending of the supplied parameters. For example, for querying all the sms messages sent and received write the followed code:

await query.querySms({
    kinds: [SmsQueryKind.Inbox, SmsQueryKind.Sent]
});

You can also query all the sms messages sent and received from a specific contact:

await query.querySms({
    address: getContactAddress()
});

Getting all Threads Conversations #

With SmsQuery you can also get the entire list of conversations:

List<SmsThread> threads = await query.getAllThreads;

Getting the Contact info #

Each conversation thread is related with a Contact. The class Contact contains all the info of a thread contact (address, photo, full name). To get access to Contact class you must import 'package:sms/contact.dart' into your dart file:

import 'package:sms/contact.dart';

void main() {
  ...
  Contact contact = threads.first.contact;
  print(contact.address);
}

Querying Contact #

You can also query a contact by its address (phone number):

import 'package:sms/contact.dart';

void main() {
  ContactQuery contacts = new ContactQuery();
  Contact contact = await contacts.queryContact(getAddress());
  print(contact.fullName);
}
String getAddress() {...}

The Contact photo #

You can retrieve the photo of the contact (full size or thumbnail):

...
Photo photo = contact.photo;
Uint8List thumbnail = await photo.readBytes();
Uint8List fullSize = await photo.readBytes(fullSize: true);

Note: the use of await keyword means that readBytes() is resolved asynchronously and a Future is returned.

User Profile #

Some times it is useful to request basic info of the phone owner, like the contact photo, addresses, etc.

import 'package:sms/contact.dart';

UserProfileProvider provider = new UserProfileProvider();
UserProfile profile = await provider.getUserProfile();
print(profile.fullName);

Sending SMS #

What about sending a SMS? All you have to do is to create an instance of the SmsSender class:

import 'package:sms/sms.dart';

void main() {
  SmsSender sender = new SmsSender();
  String address = getAddress();
  ...
  sender.sendSms(new SmsMessage(address, 'Hello flutter!'));
}

To be notified when the message is sent and/or delivered, you must add a listener to your message:

import 'package:sms/sms.dart';

void main() {
	SmsSender sender = new SmsSender();
	String address = getAddress();
	...
	SmsMessage message = new SmsMessage(address, 'Hello flutter!');
	message.addStateListener((state) {
		if (state == SmsMessageState.Sent) {
			print("SMS is sent!");
		} else if (state == SmsMessageState.Delivered) {
			print("SMS is delivered!");
		}
	});
	sender.sendSms(message);
}

Receiving SMS #

If you want to be notified for incoming new messages you must subscribe to an instance of the SmsReceiver class:

import 'package:sms/sms.dart';

void main() {
  SmsReceiver receiver = new SmsReceiver();
  receiver.onSmsReceived.listen((SmsMessage msg) => print(msg.body));
}

Roadmap #

  • SMS Receiver
  • SMS Sender
  • SMS Delivery
  • SMS Query
  • SMS Thread
  • MMS Receiver
  • MMS Sender
  • MMS Delivery
  • MMS Query
  • Multi Sim Card
  • Contact
  • Contact Photo (full size, thumbnail)
  • User profile (basic info)

Contributions #

Any contribution is welcome.

117
likes
0
pub points
91%
popularity

Publisher

unverified uploader

SMS library

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on sms