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.