Search
 
SCRIPT & CODE EXAMPLE
 

DART

flutter firestore crud

import 'package:cloud_firestore/cloud_firestore.dart';

abstract class OurDatabase {
  static final db = FirebaseFirestore.instance;

  static Future create(String collection, String document, Map<String, dynamic> data) async {
    await db.collection(collection).doc(document).set(data);
  }

  static Future<Map<String, dynamic>?> read(String collection, String document) async {
    final snapshot = await db.collection(collection).doc(document).get();
    return snapshot.data();
  }

  static Future update(String collection, String document, Map<String, dynamic> data) async {
    await db.collection(collection).doc(document).update(data);
  }

  static Future replace(String collection, String document, Map<String, dynamic> data) async {
    await db.collection(collection).doc(document).set(data);
  }

  static Future delete(String collection, String document) async {
    await db.collection(collection).doc(document).delete();
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: operators in dart 
Dart :: DartPad localStorage 
Dart :: flutter column main axis alignment 
Dart :: open another page with routeflutter 
Dart :: flutter vertical space between containers 
Dart :: flutter duration to string 
Dart :: dart data class generator 
Dart :: convert object to int flutter 
Dart :: foreach loop in list in dart 
Dart :: get one document firestore flutter dart 
Dart :: flutter status bar color 
Dart :: sizedbox flutter 
Dart :: mainAxisAlignment vs crossAxisAlignment flutter 
Dart :: flutter pretext on textfield 
Dart :: bottomsheet shape flutter 
Dart :: set orientation to landscape flutter 
Dart :: dispose in flutter widget 
Dart :: flutter date input field 
Dart :: conditionalstatement in widget flutter 
Dart :: Running Gradle task assembleDebug.... 
Dart :: sliver persistent header 
Dart :: get string from future string flutter 
Dart :: uinstall php server on ubuntu 
Dart :: dart singleton 
Dart :: get in dart 
Dart :: Flutter: How do you make a card clickable? 
Dart :: Drawer Header set text positon 
Dart :: most used extentions for flutter 
Dart :: change notifier flutter example 
Dart :: android studio not detecting new package in flutter 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =