0

I was trying to change the below flutter firebase realtime database code to cloud firestore, but I am getting this errors...

  1. error: The method 'child' isn't defined for the type 'Query'.
  2. error: The method 'push' isn't defined for the type 'Query'.
DatabaseReference databaseReference = FirebaseDatabase.instance.reference().child('Products');          

String uploadId = databaseReference.push().key;
HashMap map = new HashMap();
map['productName'] = productName;
map['productCat'] = selectedCat;
map['startingPrice'] = int.parse(startingPrice);
map['gapPrice'] = int.parse(gapPrice);
map['imageSrc'] = url;
map['timeStamp'] = DateTime.now().toString();

databaseReference.child(uploadId).set(map);

1 Answer 1

1

That is because this is not how you add a document with cloud Firestore. Please look at this reference to add a document.

Your example would look like this:

final products = Firebase.instance.collection('products');
products.add({
  'productName': productName,
  ...
});
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.