Reading and Writing Data
Learn how to read and write data to the Realtime Database.
We'll cover the following...
Setting up
To get started with reading and writing data in Realtime Database, we need to first create the database in our project in the Firebase Console.
Firebase
Follow the steps below:
Navigate to the “All products” menu and select “Realtime Database.”
Continue by clicking “Create Database.”
Select the preferred location.
Select test mode to enable a quick setup.
The step-by-step guide to enabling Realtime Databases is illustrated in the following slides:
Flutter project
We then need to integrate Realtime Database in our Flutter app using the following steps:
- First, add the
firebase_database
package to thepubspec.yaml
file in the flutter dependancies section. - Next, add
databaseURL
to themain.dart
file on the web Firebase initialization. The following code snippet show how this is achieved:apiKey: "AIzaSyAmOB_-8DIEIwJEOvrM2a8C6RE-KbvSDDc", projectId: "educative-9", storageBucket: "educative-9.appspot.com", //Here is the line databaseURL: "https://educative-9-default-rtdb.firebaseio.com", messagingSenderId: "14205101883", appId:"1:14205101883:web:7c0db5d88bc2dc0310791e",
Note: The keys we’ve mentioned (
apiKey
,projectId
,storageBucket
,messagingSenderId
,appId
) are all part of the Firebase project configuration. These keys are required to initialize and authenticate our Firebase project when interacting with Firebase services on web platforms. ...