This repository houses a template for creating a Flutter application that leverages the power of Firebase.
The Flutter directory includes Dart code for using the following Firebase services:
- Authentication
- Cloud Firestore
- Cloud Functions
The FirebaseCloudFunctions directory includes JavaScript code for implementing:
- an HTTP Firebase Cloud Function.
A demo of the Flutter app that this repository powers can be found here.
To use this project:
- In a shell, run the command
git clone https://github.com/Ericthestein/Firebase-Flutter-Template.git
. - Follow the relevant steps below to set up the Flutter portion and/or the Firebase Cloud Functions portion.
To set up Firebase for this project:
- Head over to the Firebase website, log in / sign up, and create a new project.
For help getting started with Flutter, check out this tutorial.
Four main actions should be completed to get the Flutter portion of this project up and running:
- Run
firebase init
and select the Hosting option (make sure that you runcd Flutter
to get into the Flutter directory if you are starting in the root directory). When asked about making your web app a single-page app, select Yes If asked to overwrite index.html, select No - Download all necessary libraries by running
flutter pub get
. - Modify index.html to include your project's configuration.
- The code can be generated by going to your Firebase Project -> Settings -> General -> Your Apps -> Web Apps -> CDN
- For more help, check out this link
- Create a Cloud Firestore datastore by going to your Firebase Project -> Cloud Firestore -> Create Database
The Authentication service from Firebase is mostly used in AuthenticationPage.dart. There, users can register for an account in our app or sign into an existing account using an email and password. Upon authentication, the user is allowed access to the other pages.
The Cloud Firestore service from Firebase is used in CloudFirestorePage.dart. There, users can participate in an election to finally settle the following age-old question: cats or dogs (using photos of the pets of yours truly as reference)? When the vote buttons are pressed, the corresponding values in the provisioned Cloud Firestore service are modified, and every time a data update occurs, the client app listens and updates its display to reflect the new vote values.
The Cloud Functions service from Firebase is used in CloudFunctionsPage.dart. There, users can use an HTTP function to send a preconfigured email to a given email address (see below). It includes an anti-spam measure to force users to wait at least a minute before sending another email in their current session.
For help getting started with node.js, check out this tutorial.
To set up the included Cloud Functions:
- Run
firebase init
and select the Cloud Functions option (make sure that you runcd FirebaseCloudFunctions
to get into the FirebaseCloudFunctions directory if you are starting in the root directory). - Modify index.js to include the credentials for your email bot account (see below). Make sure your account can be logged into through unsecure services.
- Enable the Blaze plan in your Firebase account and add a billing account (though this is required for Cloud Functions to be used, Firebase offers a free tier that will be used up before you are charged).
EmailSender, the included HTTP Firebase Cloud Function, can be used to send a preconfigured email to a given email address via a REST API call (or by using the Firebase Cloud Functions library for Flutter, as we are doing). It works by using Nodemailer, a library for sending automatic emails.
This project is licensed under the MIT License - see LICENSE.md for more details.