launchers 0.4.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

launchers #

pub package Coverage Status

A Flutter plugin that makes it easy to link into other apps, including email, sms, WhatsApp, etc. This plugin is extensible, but a list of included providers can be found at the bottom of this README:

Usage #

By provider

You can open a specific provider (or app)

final Email email = Email(
  body: "Hello, world",
  subject: "My first message",
  recipients: ["mrroboto@gmail.com"],
  attachmentPath: attachment,
);

/// In this case, [gmailProvider] is one of the packaged providers that comes with the plugin.  You 
/// can also register your own
LaunchService().launchProvider(gmailProvider.providerKey, email);

By operation

You can also specify an operation and the plugin will attempt to find a suitable launcher:

final Email email = Email(
  body: "Hello, world",
  subject: "My first message",
  recipients: ["mrroboto@gmail.com"],
  attachmentPath: attachment,
);

/// In this case [composeEmailOperation] is a statically defined operation schema that a provider 
/// can 'implement'.  Out of the box, there are two providers for email, a native email provider that 
/// opens the devices defaul mail program, or the GMail app
final results = await LaunchService().launch(composeEmailOperation, email);

Included Providers #

  • sms
  • phone
  • facebook
  • gmail
  • instagram
  • twitter
  • linkedin
  • snapchat
  • pinterest
  • paypal
  • cashapp
  • venmo

[0.4.5] - Official publish #

[0.4.4] - Initial release #

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:launchers/launchers.dart';
import 'package:logging/logging.dart';
import 'package:logging_config/logging_config.dart';

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

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

class _MyAppState extends State<MyApp> {
  String attachment;

  @override
  void initState() {
    super.initState();
    configureLogging(
        LogConfig(logLevels: {"": Level.FINE}, handler: LoggingHandler.dev()));
  }

  final _recipientController = TextEditingController(
    text: 'example@example.com',
  );

  final _subjectController = TextEditingController(text: 'The subject');

  final _bodyController = TextEditingController(
    text: 'Mail body.',
  );

  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

  Future<void> send() async {
    final Email email = Email(
      body: _bodyController.text,
      subject: _subjectController.text,
      recipients: [_recipientController.text],
      attachmentPath: attachment,
    );

    Iterable<String> platformResponse;

    try {
      final results =
          await LaunchService().launch(composeEmailOperation, email);
      print(results);
      platformResponse = results.allAttempts.entries.map((entry) {
        return "Provider = ${entry.key}\nResult = ${entry.value}";
      });
    } catch (error, stack) {
      print(error);
      print(stack);
      platformResponse = ["Error: $error"];
    }

    if (!mounted) return;

    platformResponse.forEach((message) {
      print(message);
      print("-------------");
      _scaffoldKey.currentState.showSnackBar(SnackBar(
        content: Text("$platformResponse"),
        duration: Duration(seconds: 5),
      ));
    });
  }

  @override
  Widget build(BuildContext context) {
    final Widget imagePath = Text(attachment ?? '');
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.red),
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Text('Plugin example app'),
          actions: <Widget>[
            IconButton(
              onPressed: send,
              icon: Icon(Icons.send),
            )
          ],
        ),
        body: SingleChildScrollView(
          child: Center(
            child: Padding(
              padding: EdgeInsets.all(8.0),
              child: Column(
                mainAxisSize: MainAxisSize.max,
                // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _recipientController,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Recipient',
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _subjectController,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Subject',
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _bodyController,
                      maxLines: 10,
                      decoration: InputDecoration(
                          labelText: 'Body', border: OutlineInputBorder()),
                    ),
                  ),
                  imagePath,
                ],
              ),
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton.extended(
          icon: Icon(Icons.camera),
          label: Text('Add Image'),
          onPressed: _openImagePicker,
        ),
      ),
    );
  }

  void _openImagePicker() async {
    File pick = await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      attachment = pick.path;
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  launchers: ^0.4.6

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:launchers/launchers.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
equatable ^1.0.2 1.1.1
flutter 0.0.0
logging ^0.11.4 0.11.4
logging_config ^0.4.7 0.4.7
pedantic ^1.8.0+1 1.9.0
url_launcher ^5.4.2 5.4.2
Transitive dependencies
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
isolate 2.0.3
js 0.6.1+1
meta 1.1.8
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
url_launcher_macos 0.0.1+4
url_launcher_platform_interface 1.0.6
url_launcher_web 0.1.1+1
vector_math 2.0.8
worker_service 0.5.2
Dev dependencies
flutter_test