Free Mobile for Dart

Release License Build

Send SMS messages to your Free Mobile account, in Dart.

To use this library, you must have enabled SMS Notifications in the Options of your Subscriber Area.

Requirements

The latest Dart SDK and Pub versions.

Installing via Pub

Depend on it

Add this to your package's pubspec.yaml file::

dependencies:
  free_mobile: *

Install it

You can install the dependencies from a command prompt:

$ pub get

Usage

This package provides a single class, Client, which allow to send messages to your mobile phone by using the sendMessage() method:

import 'package:free_mobile/free_mobile.dart';

Future main() async {
  try {
    var client = new Client('<user name>', '<identification key>');
    await client.sendMessage('Hello World!');
    print('The message was sent successfully.');
  }
  
  catch (Exception error) {
    print('An error occurred: $error');
  }
}

The text of the messages will be automatically truncated to 160 characters: you can't send multipart messages using this library.

Events

The Client class triggers some events during its life cycle:

  • request : emitted every time a request is made to the remote service.
  • response : emitted every time a response is received from the remote service.

These events are exposed as Stream, you can listen to them using the on<EventName> properties:

client.onRequest.listen(
  (request) => print('Client request: ${request.url}')
);

client.onResponse.listen(
  (response) => print('Server response: ${response.statusCode}')
);

Unit tests

In order to run the tests, you must set two environment variables:

$ export FREEMOBILE_USERNAME="<your Free Mobile user name>"
$ export FREEMOBILE_PASSWORD="<your Free Mobile identification key>"

Then, you can run the test script from the command prompt:

$ pub run test

See also

License

Free Mobile for Dart is distributed under the Apache License, version 2.0.

Libraries

free_mobile

Send SMS messages to your Free Mobile account.