simple_sms 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

Simple sms #

Plugin for simple sending sms. We have developed this one, because we needed plugin that supports multiple recipients.

Getting Started #

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

For help on editing plugin code, view the documentation.

Installation and Usage #

add simple_sms to your pubspec.yaml

dependencies:
  flutter:
      sdk: flutter
  simple_sms:

then run flutter packages get

Sending sms #

create instance of SimpleSms

final SimpleSms simpleSms = SimpleSms();

and then supply List<String> contacts and String smsBody to it's sendSms() function

simpleSms.sendSms(contacts, smsBody);

[0.0.1] - 03-07-2018.

  • simple sms url launch with multiple recipients support

[0.0.2] - 16-08-2018.

  • add support for Dart 2

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:simple_sms/simple_sms.dart';

void main() => runApp(SimpleSmsExampleApp());

class SimpleSmsExampleApp extends StatefulWidget {
  @override
  _SimpleSmsExampleAppState createState() => _SimpleSmsExampleAppState();
}

class _SimpleSmsExampleAppState extends State<SimpleSmsExampleApp> {
  final contactTextFieldController = TextEditingController();
  final smsTextFieldController = TextEditingController();
  final List<String> contacts = [];
  String recipients;
  final RegExp exp = RegExp(r'([(+]*[0-9]+[()+. -]*)');
  static const double defaultPadding = 8.0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Simple sms example app'),
        ),
        body: Builder(
          builder: (BuildContext context) {
            return Container(
              child: Center(
                child: Column(
                  children: <Widget>[
                    Padding(
                      padding: const EdgeInsets.all(defaultPadding),
                      child: Row(
                        children: <Widget>[
                          Flexible(
                            child: TextField(
                              keyboardType: TextInputType.phone,
                              decoration:
                                  InputDecoration(hintText: '+420123456789'),
                              controller: contactTextFieldController,
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.all(defaultPadding),
                            child: RaisedButton(
                              onPressed: () {
                                if (_validateContact(
                                    //whole this onPressed is terrible :/ didnt figure out how to display Snackbar outside of Build method
                                    contactTextFieldController.text)) {
                                  _addContact(contactTextFieldController.text);
                                  Scaffold.of(context).showSnackBar(SnackBar(
                                        content: Text('Contact added'),
                                      ));
                                } else {
                                  Scaffold.of(context).showSnackBar(SnackBar(
                                        content: Text(
                                            'Contact contains invalid characters'),
                                      ));
                                }
                              },
                              child: Text('add contact'),
                            ),
                          ),
                        ],
                      ),
                    ),
                    contacts.length > 0 ?
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Row(
                        children: <Widget>[
                          Flexible(
                              child: Text(
                            'Recipients: \n $recipients',
                            overflow: TextOverflow.ellipsis,
                                maxLines:  10,
                          )),
                        ],
                      ),
                    ) : Container(),
                    Padding(
                      padding: const EdgeInsets.all(defaultPadding),
                      child: Row(
                        children: <Widget>[
                          Flexible(
                            child: TextField(
                              controller: smsTextFieldController,
                              decoration: InputDecoration(hintText: 'SMS body'),
                              maxLines: null,
                              keyboardType: TextInputType.multiline,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(defaultPadding),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Center(
                            child: RaisedButton(
                              onPressed: () {
                                _sendSms(contacts, smsTextFieldController.text);
                              },
                              child: Text('Send SMS'),
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                ),
              ),
            );
          },
        ),
      ),
    );
  }

  _addContact(String contact) {
    contacts.add(contact);
    contactTextFieldController.text = '';
    setState(() {
      recipients = contacts.join(', \n');
    });
  }

  bool _validateContact(String contact) {
    if (exp.firstMatch(contact) == null) {
      return false;
    } else {
      return true;
    }
  }

  _sendSms(List<String> contacts, String smsBody) async {
    final SimpleSms simpleSms = SimpleSms();
    simpleSms.sendSms(contacts, smsBody);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  simple_sms: ^0.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:simple_sms/simple_sms.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
55
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/simple_sms.dart.

Run flutter format to format lib/simple_sms.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is getting outdated. (-15.34 points)

The package was last published 60 weeks ago.

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

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8