Home > Software engineering >  How can I update array value on cloud firestore using firedart package on flutter?
How can I update array value on cloud firestore using firedart package on flutter?

Time:09-01

My code:

import 'package:firedart/firedart.dart';
import 'package:firedart/firestore/firestore.dart';
class FirestoreMethods{
final _firestore = Firestore.instance;
Future<void> likePost(String postId, String uid, List likes) async {
    try {
      if (likes.contains(uid)) {
        _firestore.collection('posts').document(postId).update({
          'likes':  FieldValue.arrayRemove([uid])
        });
      } else {
        _firestore.collection('posts').document(postId).update({
          'likes': FieldValue.arrayUnion([uid])
        });
      }
    } catch (e) {
      print(e.toString());
    }
  }
}

I want to update array value on firestore using firedart package. But it shows error saying "undefined name 'FieldValue' ".

CodePudding user response:

From looking at issue #29 on the source repo, it looks like arrayUnion is current not supported in the firedart library. In a comment, the creator of the library is asking for a pull request to add it and I left a comment on how this operator maps to the REST API.

  • Related