# Configure firestore

Follow the steps below to configure firestore

# Create database

  1. Open firebase console of the Project
  2. Click Firestore Database from sidebar
  3. Click Create Database button
  4. Click next
  5. Click enable
  6. 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

  1. Add latest firebase_core (opens new window) package to pubspec.yaml
  2. Add latest cloud_firestore (opens new window) package to pubspec.yaml
  3. Click Pub get on Android Studio
  4. 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();
  }
}

  1. Download firestore folder from here (opens new window) and add it inside lib/datastore/ folder