Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I perform a transaction in firebase_database in Flutter?

How do I perform an atomic read/write transaction in firebase_database in Flutter?

like image 597
Luke Pighetti Avatar asked Jul 14 '18 23:07

Luke Pighetti


Video Answer


1 Answers

A transaction is an atomic read/write on a piece of data in a Firebase Realtime Database or Cloud Firestore.

Flutter is a mobile development framework that uses the Dart language.

This is how you perform a transaction using the firebase_database package in a Flutter app.

final dataRef = database.reference().child('path/to/data');

dataRef.runTransaction((MutableData transaction) async{
    transaction.value = (transaction.value ?? 0) + 1;
    return transaction;
});
like image 199
Luke Pighetti Avatar answered Oct 23 '22 23:10

Luke Pighetti