Amazon.co.uk Widgets

Log in

X
Cloud Firestore - Real-time updates, powerful queries and automatic scaling

This is the ninth part of my journey to build and publish a Flutter based app for the App Store and Google Play.

Cloud Firestore is a flexible, scalable database for mobile, Google. It supports hierarchical data structures, expressive queries, realtime updates, offline support, and seamless integration with other Firebase and Google Cloud products. It is pretty perfect for mobile apps.

TL:DR –  This article goes through the setup steps required to get it going.

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 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

  • 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).
  • Click Create project.
  • Name the project
  • Optionally enable Google Analytics
  • Enable Anonymous login which allows the application to silently sign in users.
  • In the Firebase console Develop section, select 'Database'
  • Click Create database in the Cloud Firestore pane.
  • 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.