FieldValue arrayUnion and Cloud FireStore with Flutter

The other way if you have List of objects

Future<void> updateUserNewGroup(List<Group> data , String id) {

    List<Map> list=new List();

    if(data !=null && data.isNotEmpty){
        data.forEach((grp){
            list.add(grp.toJson());
        });
    }


    return ref.document(id).updateData({"groups": FieldValue.arrayUnion(list)}) ;
}

New FlutterFire Update 2021

With the newest FlutterFire update there where lots of updates at the API but thankfully it hasn't changed that much for this problem. I'm talking about the newest plugins of Firebase for Flutter and specifically every plugin that is compatible with the new firebase_core ^0.7.0. So the code looks similar:

FirebaseFirestore.instance
.collection("YourCollection")
.doc("YourDocument")
.update({
      "anArray": FieldValue.arrayUnion(["data", "to", "append"])
    });

I have found a solution. Try this:

 Firestore.instance
.collection('YourCollection')
.document('YourDocument')
.updateData({'array':FieldValue.arrayUnion(['data1','data2','data3'])});

If it still doesn't work, try to update your Firebase.

First open a terminal fetched to your flutter project, then:

cd ios
pod update Firebase

This solution is only for mac users.