flutter_sms 0.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 87

flutter_sms

alt-text-1

Description

Flutter Plugin for sending SMS and MMS on Android and iOS. If you send to more than one person it will send as MMS. On the iOS if the number is an iPhone and iMessage is enabled it will send as an iMessage.

How To Use

You can send multiple ways:

  1. Message and No People
  2. People and No Message
  3. Message and People

This will prefil the correct fields.

Setup

Android

Add this to your AndroidManifest.xml

<uses-permission android:name="android.permission.SEND_SMS"/>

iOS

Good to go!

Example

Make sure to Install and Import the Package.

import 'package:flutter_sms/flutter_sms.dart';

Create a function for sending messages.

String _message = "";

void _sendSMS(String message, List<String> recipents) async {
    String _result =
        await FlutterSms.sendSMS(message: message, recipients: recipents);
    setState(() => _message = _result);
}

You can quickly send the message with this function.

_sendSMS("Here is a test Message", ["5555543454", "78467477788"])

Screenshots

iOS SMSAndroid MMS
alt-text-1alt-text-2

You can find other screenshots here.

0.0.3

  • Bug Fix for iOS Simulator Error

0.0.2

  • Fixing Version

0.0.1

  • SMS and MMS for Android and iOS

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_sms/flutter_sms.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  TextEditingController _controllerPeople, _controllerMessage;
  String _message, body;
  List<String> people = [];

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    _controllerPeople = TextEditingController();
    _controllerMessage = TextEditingController();
  }

  void _sendSMS(String message, List<String> recipents) async {
    String _result =
        await FlutterSms.sendSMS(message: message, recipients: recipents);
    setState(() => _message = _result);
  }

  Widget _phoneTile(String name) {
    return Padding(
      padding: const EdgeInsets.all(3.0),
      child: Container(
          decoration: BoxDecoration(
              border: Border(
            bottom: BorderSide(color: Colors.grey[300]),
            top: BorderSide(color: Colors.grey[300]),
            left: BorderSide(color: Colors.grey[300]),
            right: BorderSide(color: Colors.grey[300]),
          )),
          child: Padding(
            padding: EdgeInsets.all(4.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                IconButton(
                  icon: Icon(Icons.close),
                  onPressed: () => setState(() => people.remove(name)),
                ),
                Padding(
                  padding: const EdgeInsets.all(0.0),
                  child: Text(
                    name,
                    textScaleFactor: 1.0,
                    style: TextStyle(fontSize: 12.0),
                  ),
                )
              ],
            ),
          )),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('SMS/MMS Example'),
        ),
        body: ListView(
          children: <Widget>[
            people == null || people.isEmpty
                ? Container(
                    height: 0.0,
                  )
                : Container(
                    height: 90.0,
                    child: Padding(
                      padding: const EdgeInsets.all(3.0),
                      child: ListView(
                        scrollDirection: Axis.horizontal,
                        children:
                            List<Widget>.generate(people.length, (int index) {
                          return _phoneTile(people[index]);
                        }),
                      ),
                    ),
                  ),
            ListTile(
              leading: Icon(Icons.people),
              title: TextField(
                controller: _controllerPeople,
                decoration: InputDecoration(labelText: "Add Phone Number"),
                onChanged: (String value) => setState(() {}),
              ),
              trailing: IconButton(
                icon: Icon(Icons.add),
                onPressed: _controllerPeople.text.isEmpty
                    ? null
                    : () => setState(() {
                          people.add(_controllerPeople.text.toString());
                          _controllerPeople.clear();
                        }),
              ),
            ),
            Divider(),
            ListTile(
              leading: Icon(Icons.message),
              title: TextField(
                decoration: InputDecoration(labelText: " Add Message"),
                controller: _controllerMessage,
                onChanged: (String value) => setState(() {}),
              ),
              trailing: IconButton(
                icon: Icon(Icons.save),
                onPressed: _controllerMessage.text.isEmpty
                    ? null
                    : () => setState(() {
                          body = _controllerMessage.text.toString();
                          _controllerMessage.clear();
                        }),
              ),
            ),
            Divider(),
            ListTile(
              leading: Icon(Icons.text_fields),
              title: Text(body ?? "No Message Set"),
              subtitle: people == null || people.isEmpty
                  ? null
                  : Text(people.toString()),
              trailing: IconButton(
                icon: Icon(Icons.send),
                onPressed: () {
                  if ((people == null || people.isEmpty) ||
                      (body == null || body.isEmpty)) {
                    setState(() =>
                        _message = "At Least 1 Person or Message Required");
                  } else {
                    _sendSMS(body, people);
                  }
                },
              ),
            ),
            Divider(),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(12.0),
                  child: Text(
                    _message ?? "No Data",
                    maxLines: null,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_sms: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_sms/flutter_sms.dart';
  
Version Uploaded Documentation Archive
0.0.3 Aug 16, 2018 Go to the documentation of flutter_sms 0.0.3 Download flutter_sms 0.0.3 archive
0.0.2 Aug 16, 2018 Go to the documentation of flutter_sms 0.0.2 Download flutter_sms 0.0.2 archive
0.0.1 Aug 16, 2018 Go to the documentation of flutter_sms 0.0.1 Download flutter_sms 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8