# Configure firestore
Follow the steps below to configure firestore
# Create database
- Open firebase console of the Project
- Click Firestore Database from sidebar
- Click
Create Databasebutton - Click next
- Click enable
- Click Rules from tab bar and change rule to this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null;
allow delete: if request.auth.uid == userId;
}
match /deletedUsers/{userId} {
allow read, write: if request.auth != null;
allow delete: if request.auth.uid == userId;
}
}
}
# Connect with flutter app
- Add latest firebase_core (opens new window) package to pubspec.yaml
- Add latest cloud_firestore (opens new window) package to pubspec.yaml
- Click
Pub geton Android Studio - Initialize firebase by adding following code on
configure/initializer.dart
import '../datastore/sqlite/sqlite.dart';
import 'package:firebase_core/firebase_core.dart';
import '../datastore/shared_pref/shared_pref.dart';
class Initializer {
initialize() async {
await initializeFirebase();
await initializeDatastore();
}
/// Initialize Firebase
initializeFirebase() async {
await Firebase.initializeApp();
}
/// Initialize sqlite and shared preferences
initializeDatastore() async {
/// Initializes shared_preference
SharedPref().sharedPrefInit();
/// Initialize sq-lite
final db = SqliteDB();
await db.countTable();
}
}
- Download firestore folder from here (opens new window) and add it inside
lib/datastore/folder