SendGrid Flutter

This tutorial is an extension of the [SendGrid Transactional Email Guide](/lessons/sendgrid-transactional-email-guide/). You must have the Cloud Functions deployed to start sending email from your frontend app.

Initial Setup

To support both iOS and Android, you will need to follow the Firebase installation guide and have the cloud_functions and auth plugins from FlutterFire installed.

file_type_flutter pubspec.yaml
    sdk: flutter

  firebase_core: 0.4.0
  firebase_auth: 0.11.1+7
  cloud_functions: 0.4.0+2

Transactional Email Widget

The widget below creates a new user with email/pass auth and provides a button to send a transactional email (via callable functions) from the app.

file_type_dartlang main.dart
class TransactionalEmail extends StatefulWidget {
  createState() => _TransactionalEmailState();

class _TransactionalEmailState extends State<TransactionalEmail> {

  final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
    functionName: 'genericEmail',

  final FirebaseAuth auth = FirebaseAuth.instance;

  FirebaseUser user;

  String emailAddress = '[email protected]';

    initState() {
      auth.onAuthStateChanged.listen((u) { 
        setState(() => user = u);

  sendEmail() {
      'text': 'Sending email with Flutter and SendGrid is fun!', 
      'subject': 'Email from Flutter'
    }).then((res) => print(;

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Send Email with SendGrid and Flutter'),),
      body: Center(
        child: Column(
          children: <Widget>[
            if (user != null) ...[
              FlatButton(child: Text('SignOut'), onPressed: auth.signOut),
              FlatButton(child: Text('Send Email with Callable Function'), onPressed: sendEmail)

            else ...[
              FlatButton(child: Text('Login'), onPressed: () => auth.createUserWithEmailAndPassword(email: emailAddress, password: 'demoPass23'))

Q&A Chat