Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 30, 2022 09:46 am GMT

Keeping It Simple: Integrate Firebase and Agora.io in your Flutter Projects (Part 2)

This post is the second part of the three-part article on integrating Firebase and Agora.io in a Flutter Project. In the first part, weve specified what Flutter is and how to create and run the project.
In this part, well be integrating Firebase and persist user data.

Backend as a Service (BaaS)

As the backend for Flutter, we decided to use Firebase. Firebase is a Backend-as-a-Service platform from Google.

Firebase provides a variety of services, including:

  • Real-time database: This is a cloud-hosted NoSQL database that gives the developer the ability to store data and sync it between users in real time. If the app goes offline, the data is still available.

  • Authentication: Firebase Authentication makes sure that the app can be built with secure authentication systems and enhances the login experience. Not only can you use your local login credentials but Google, Facebook, GitHub and much more services can be used to log in.

  • Reporting and Monitoring: The reporting and monitoring tools that Firebase provides are impressive. It connects to Google Analytics to provide free, unlimited reports about user behaviors, which gives the developer the ability to have better decision-making performance. Besides reporting, Firebase Performance Monitoring service allows you to have an insight into the performance characteristics of your app.

Firebase Console

Impressive right? Lets take a look at how we used it in our app.

First, we need to understand how we need to connect our Flutter app to the Firebase service. Take a look at How to set up Firebase.

Now everything is set up, lets start to use the real-time database. In this small tutorial, we are going to tackle how we can save to and read from the database.

In Firebase, were going to make our first collection named notes.
In the screenshot below, youll see a few more as an example.

Database Collection

We are going to add the firebase packages to our pubspec.yaml file. Lets also add the authentication package.

Always search for the latest version of the packages on https://pub.dev/

dependencies: flutter:   sdk: flutter firebase_core: ^1.12.0 firebase_auth: ^3.3.7

To use the package were going to import it into our dart file.

import 'package:cloud_firestore/cloud_firestore.dart';import 'package:firebase_auth/firebase_auth.dart';

In the code below you see how we can reference our notes collection and add a new item. Its that simple.

CollectionReference ref =     FirebaseFirestore.instance.collection('notes');User? user = FirebaseAuth.instance.currentUser;
ref.doc(user?.uid)   .collection('notes')   .add({ 'title':'Flutter Demo', 'content':'First Note', 'owner' : user?.uid});

For more advanced usage of realtime databases check Realtime Database: Overview.

Why did we choose Firebase?

Well, both Flutter and Firebase are Google products. This makes it convenient for the developer, connections are easily programmed (as you saw in the tutorial!). Firebase SDK and UI libraries are instant and also quite stable.

It gives the developer the experience of an easy and fast development and the user a smooth usage of the app.

Whats next?

Were almost there. There is only one important thing on our TODO list:

  • Integrate Agora.io for our Real-Time Communication Needs.

In part 3 well be integrating Agora.io in our project.


Original Link: https://dev.to/souhaibafouallah/keeping-it-simple-integrate-firebase-and-agoraio-in-your-flutter-projects-part-2-13gi

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To