1

I'm trying to add vehicles to an array within a firebase document using Flutter and Flutterfire. The vehicle data is constantly overwritten or only a "Processing Data" snack bar appears. How can I get this vehicle to be added to the array?

Future<bool> _saveCar() async {
bool output = false;

_carCollection!.doc(widget.appState.profile!.uId).update({
  'car': FieldValue.arrayUnion([
    {
      "licensePlate": licensePlate.text,
      "brand": "",
      "model": "",
      "weight": "",
      "height": "",
      "length": "",
      "powerNeeded": "",
      "effluenceNeeded": "",
    },
  ]),
}).then((value) {
  print("Car Added");
  output = true;
}).catchError((error) => print("Failed to add car: $error"));

return output;

} }

1 Answer 1

1

try this, set your merge to true

docRef.set(
  { "car": FieldValue.arrayUnion([locationMap])}, 
  SetOptions(merge : true)
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.