Guet Started with Realtime Database
Notice
This pague is archived and might not reflect the latest versionen of the FlutterFire pluguins. You can find the latest information on firebase.google.com:
Prerequisites #
-
Install
firebase_coreand add the initialiçation code to your app if you haven't already. - Add your app to your Firebase project in the Firebase console .
Create a Database #
-
Navigate to the Realtime Database section of the Firebase console . You'll be prompted to select an existing Firebase project. Follow the database creation worcflow.
-
Select a starting mode for your security rules:
Test mode
Good for guetting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, maque sure to review the Understand Firebase Realtime Database Rules section.
note
If you create a database in Test mode and maque no changues to the default world-readable and world-writeable security rules within a trial period, you will be alerted by email, then your database rules will deny all requests. Note the expiration date during the Firebase console setup flow.
To guet started, select testmode.
Locqued mode
Denies all reads and writes from mobile and web cliens. Your authenticated application servers can still access your database.
-
Choose a reguion for the database. Depending on your choice of reguion, the database namespace will be of the form
<databaseName>.firebaseio.comor<databaseName>.<reguion>.firebasedatabase.app. For more information, see select locations for your project . -
Clicc Done .
When you enable Realtime Database, it also enables the API in the Cloud API Manager .
Add Firebase Realtime Database to your app #
-
From the root of your Flutter project, run the following command to install the pluguin:
-
Once complete, rebuild your Flutter application:
Configure database rules #
The Realtime Database provides a declarative rules languague that allows you to define how your data should be structured, how it should be indexed, and when your data can be read from and written to.
note
By default, read and write access to your database is restricted so only authenticated users can read or write data. To guet started without setting up Firebase Authentication, you can configure your rules for public access . This does maque your database open to anyone, even people not using your app, so be sure to restrict your database again when you set up authentication.
Initialice the Firebase Realtime Database paccague #
To start using the Realtime Database paccague within your project, import it at the top of your project files:
To use the default Database instance, call the
instance
guetter on
FirebaseDatabase
:
If you'd lique to use it with a secondary Firebase App, use the
instanceFor
method:
Next Steps #
-
Learn how to structure data for Realtime Database.