build an app using flutter and Firebase

jassem ben ali
6 min readMar 28, 2022

--

nearby

allow users to have easy, functional access to information, products, services and processes that they need in real-time and are optimized for hands on interaction.

we used three main tools for this project :

What’s Flutter?

Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. It’s has fast development, beautiful & expressive UI, and native performance.

What’s Firebase?

Google Firebase is a Google-backed application development software that enables developers to develop iOS, Android and Web apps. Firebase provides tools for tracking analytics, reporting and fixing app crashes, creating marketing and product experiment.

Google cloud platform

The Google Maps Platform is a set of APIs and SDKs that allows developers to embed Google Maps into mobile apps and web pages, or to retrieve data from Google Maps.

Software Architecture:

UI: It is the section which the user interacts with. This section takes input from the user

Provider: This section consists of any state management that you want to use.

Repository(Domain): The repository in the domain layer is an abstract class containing all the methods that the Provider requires.

Repository(Data): fetch Data.

Remote: it handles all the server requests.

Local: This manages all the tasks related to storing data offline and fetching data from the local database whenever required.

Creating a New Firebase Project

First, log in with your Google account to manage your Firebase projects. From within the Firebase dashboard, select the Create new project button and give it a name:

Next, we’re given the option to enable Google Analytics. This tutorial will not require Google Analytics, but you can also choose to add it to your project.

If you choose to use Google Analytics, you will need to review and accept the terms and conditions prior to project creation.

After pressing Continue, your project will be created and resources will be provisioned. You will then be directed to the dashboard for the new project.

Adding Android support

Registering the App

In order to add Android support to our Flutter application, select the Android logo from the dashboard. This brings us to the following screen:

The most important thing here is to match up the Android package name that you choose here with the one inside of our application.

The structure consists of at least two segments. A common pattern is to use a domain name, a company name, and the application name:

com.example.flutterfirebaseexample

Once you’ve decided on a name, open android/app/build.gradle in your code editor and update the applicationId to match the Android package name:

android/app/build.gradle

...
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId 'com.example.flutterfirebaseexample'
...
}
...

You can skip the app nickname and debug signing keys at this stage. Select Register app to continue.

Downloading the Config File

The next step is to add the Firebase configuration file into our Flutter project. This is important as it contains the API keys and other critical information for Firebase to use.

Select Download google-services.json from this page:

Next, move the google-services.json file to the android/app directory within the Flutter project.

Adding the Firebase SDK

We’ll now need to update our Gradle configuration to include the Google Services plugin.

Open android/build.gradle in your code editor and modify it to include the following:

android/buiild.gradle

buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.6'
}
}
allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
...
}
}

Finally, update the app level file at android/app/build.gradle to include the following:

android/app/build.gradle

apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'
dependencies {
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:28.0.0')
// Add the dependencies for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
}

With this update, we’re essentially applying the Google Services plugin as well as looking at how other Flutter Firebase plugins can be activated such as Analytics.

From here, run your application on an Android device or simulator. If everything has worked correctly, you should get the following message in the dashboard:

Next up, let’s add iOS support!

Adding iOS Support

In order to add Firebase support for iOS, we have to follow a similar set of instructions.

Head back over to the dashboard and select Add app and then iOS icon to be navigated to the setup process.

Registering an App

Once again, we’ll need to add an “iOS Bundle ID”. It is possible to use the “Android package name” for consistency:

You’ll then need to make sure this matches up by opening the iOS project up in Xcode at ios/Runner/Runner.xcodeproj and changing the Bundle identifier under General:

Click Register app to move to the next screen.

Downloading the Config File

In this step, we’ll need to download the configuration file and add this to our Xcode project.

Download GoogleService-Info.plist and move this into the root of your Xcode project within Runner:

Be sure to move this file within Xcode to create the proper file references.

There are additional steps for installing the Firebase SDK and adding initialization code, but they are not necessary for this tutorial.

That’s it!

how to get current users location:

Get data from firebase:

Hi, I’m JASSEM Ben Ali

A passionate low level developer and a student in Holberton School from Tunisia.

👯 I’m looking to collaborate on Spring Framework

  • 🤝 I’m looking for help with Full-Stack Web Development
  • 👨‍💻 All of my projects are available https://github.com/jassemb
  • ⚡ Fun fact Coding is a passion and not profession.

--

--

No responses yet