Code Monkey home page Code Monkey logo

email_launcher's Introduction

email_launcher

Flutter plugin for launching emails on mobile platforms. Support iOS and Android.

Usage

To use this plugin, add email_launcher as a dependency in your pubspec.yaml file.

Example

Email email = Email(
    to: ['[email protected],[email protected]'],
    cc: ['[email protected]'],
    bcc: ['[email protected]'],
    subject: 'subject',
    body: 'body'
);
await EmailLauncher.launch(email);

Complete example

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

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  final _toController = TextEditingController();
  final _ccController = TextEditingController();
  final _bccController = TextEditingController();
  final _subjectController = TextEditingController();
  final _bodyController = TextEditingController();

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

  @override
  void dispose() {
    _toController.dispose();
    _ccController.dispose();
    _bccController.dispose();
    _subjectController.dispose();
    _bodyController.dispose();
    super.dispose();
  }

  void _launchEmail() async {
    List<String> to = _toController.text.split(',');
    List<String> cc = _ccController.text.split(',');
    List<String> bcc = _bccController.text.split(',');
    String subject = _subjectController.text;
    String body = _bodyController.text;

    Email email = Email(to: to, cc: cc, bcc: bcc, subject: subject, body: body);
    EmailLauncher.launch(email).then((value) {
      // success
      print(value);
    }).catchError((error) {
      // has error
      print(error);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Plugin example app"),
        ),
        body: ListView(
          children: [
            _buildTextField(
                _toController, TextInputType.emailAddress, 'Enter to'),
            _buildTextField(
                _ccController, TextInputType.emailAddress, 'Enter cc'),
            _buildTextField(
                _bccController, TextInputType.emailAddress, 'Enter bcc'),
            _buildTextField(
                _subjectController, TextInputType.text, 'Enter subject'),
            _buildTextField(_bodyController, TextInputType.text, 'Enter body'),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: ElevatedButton(
                  onPressed: _launchEmail, child: Text('Launch Email')),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildTextField(TextEditingController controller,
      TextInputType inputType, String hintText) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: TextField(
        controller: controller,
        keyboardType: inputType,
        decoration: InputDecoration(
            border: OutlineInputBorder(
              borderSide: BorderSide(color: Colors.black54),
            ),
            hintText: hintText),
      ),
    );
  }
}

email_launcher's People

Contributors

echohuub avatar limedroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

email_launcher's Issues

Null safety

Will this package be upgraded to null safety?

failed building APK

Hi

I been trying to build apk in android studio. I keep having a bug because of something related to kotlin, non Null references. This seems to come from EMail_launcher plugin.

I tried many things, like changing flutter channel to Dev, upgrade last gradle version, etc....

Does someone have any clue about this ?

e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\email_launcher-1.0.0\android\src\main\kotlin\com\heqingbao\flutter\plugin\email_launcher\EmailLauncherPlugin.kt: (6, 28): Unresolved reference: NonNull
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\email_launcher-1.0.0\android\src\main\kotlin\com\heqingbao\flutter\plugin\email_launcher\EmailLauncherPlugin.kt: (25, 38): Unresolved reference: NonNull
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\email_launcher-1.0.0\android\src\main\kotlin\com\heqingbao\flutter\plugin\email_launcher\EmailLauncherPlugin.kt: (39, 32): Unresolved reference: NonNull
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\email_launcher-1.0.0\android\src\main\kotlin\com\heqingbao\flutter\plugin\email_launcher\EmailLauncherPlugin.kt: (39, 59): Unresolved reference: NonNull
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\email_launcher-1.0.0\android\src\main\kotlin\com\heqingbao\flutter\plugin\email_launcher\EmailLauncherPlugin.kt: (47, 40): Unresolved reference: NonNull

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileReleaseKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s


The plugin email_launcher could not be built due to the issue above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.