1

Okay, so I'm creating chips tiles that are stored in a Set, but when I try to upload it to firebase I get this error "Unhandled Exception: Invalid argument: Instance of '_CompactLinkedHashSet'"

I isolated the code and simplified it so it looks like this:

...

Set<String> _tags = <String>{};
_tags.add('Test1');

Firestore.instance
    .collection('tags')
    .document(tagsID)
    .setData({
  'tags': _tags,
});

...

I've tried debugging it, and I can't get it to upload so is there any other kind of way I can get the data from the set and upload it to Firebase? Another data type I can use that Firebase will accept?

John Bell
  • 13
  • 3

3 Answers3

3

Take a look at the data types that Firestore supports. Sets are not supported. You could convert your set to a JSON string, or to a list:

List<String> tagsList = List<String>.from(_tags);
Bryson Thill
  • 494
  • 4
  • 13
1

Adding on to Bryson Thill's answer, if you need to use Sets in your code, I'd recommend you use the toList() method before uploading to Firestore.

Michael Pfaff
  • 1,178
  • 1
  • 14
  • 24
-1

I would suggest you following the answer from this question: Adding an Object to Cloud Firestore using Flutter

And you can basically upload any data you want

Zhangir Siranov
  • 329
  • 2
  • 12