This is the ninth part of a journey to build and publish a Flutter™ based app.

Cloud Firestore

Today as this is being written is Flutter Day. Theres a new codelab on Cloud Firestore. Cloud Firestore is a horizontally scaling document-model NoSQL database in the cloud. It is a new codelab, so it should show best practice, and we need to store data in the cloud for our app to be useful the timing of Flutter Day could not be better! Lets follow part of the codelab to understand how to use Firestore for our app.

Create and set up a Firebase project

The codelab is going to use:

  • Firebase Authentication to easily identify your users
  • Cloud Firestore to save structured data on the Cloud and get instant notification when the data is updated
  • Firebase Hosting to host and serve your static assets

Steps to take

  1. In the Firebase console, click Add project, and name the project. Remember the project ID for your Firebase project (or click the Edit icon to set an ID).
  2. Click Create project.
  3. Name the project
  4. Optionally enable Google Analytics
  5. Enable Anonymous login which allows the application to silently sign in users.
  6. In the Firebase console Develop section, select 'Database'
  7. Click Create database in the Cloud Firestore pane.
  8. Select the Start in test mode option, and Enable

Name the project

Firebase Console Setup screen shot

Enable Google Analytics (Optional).

Firebase Console Enable Analytics screen shot

Firebase console (Optional).

Firebase Console screen shot

Enable anonymous guest accounts

Firebase Console screen shot

Cloud Firestore

Cloud firestore is specifically designed to allow you to store and sync app data at global scale.

See also : Explainer video, Documentation, Cloud Firestore website.

Check your email for confirmation

If all went well you'll get a nice confirmation email too.

"Welcome to Firebase! You're now part of a community of hundreds of thousands of developers using Firebase to build better mobile and web apps, as well as grow their businesses. Congrats on creating your first project."
Create Database

Firebase Console 'Create database' screen shot

Start in test mode. Note the warning - this database will need to be secured for production use.

Firebase Console screen shot

Cloud Firestore The locations cannot be changed so if geographic location is important for example for data protection then it is important to pick an appropriate one. This is an app for the UK so europe-west2 was chosen as it is in London.

Firebase Console screen shot

Thats the Create and set up a Firebase project part of the codelab completed.

Clone the GitHub repository

Lets take a look at the codelab code. From the command line: git clone This email address is being protected from spambots. You need JavaScript enabled to view it.:FirebaseExtended/codelab-friendlyeats-flutter friendlyeats-flutterfolder cd friendlyeats-flutter.

  • Import the project into Android Studio.
  • Locate lib/src/model/data.dart which is were the Firestore logic resides.

Firebase and Flutter command line interface (CLI).

The Firebase CLI is required in order to use Firebase dev tools.

    Dependencies on third party utilities or projects need to be managed Ideally you should keep a list of them and understand any cost implications. It is important to look at the dependencies maturity, licensing, and rate of change to make an assessment as to whether it needs to be added. Ideally you don't want to add tons of dependencies t your project but some, like this one, are unavoidable.

  • Install the CLI using npm -g install firebase-tools
  • Verify the installation using firebase --version. It should return the version number if successful.
  • Authorize the Firebase CLI by running firebase login

    Firebase CLI Authorisation screen shot

  • Close the success window
  • Associate the app with the Firebase project using firebase use --add in your app directory
  • Select the database you set up before and an alias of 'default'
  • Thats it!

Next we will set up the initial information for the listings for the apps for iOS in App Store Connect, and for Android in Google Play so that we can get the information required to connect them to Firebase.