0
votes

I have a class that has one embedded array as well as a couple of objects. I can't figure out how to create/update and read to and from Cloud Firestore. I'm using flutter.

class ArtistModal {
 final String artistName;
 final String artistImage;
 final String role;

ArtistModal({
 required this.artistName,
 required this.artistImage,
 required this.role,
});

I am trying to embedded artistModal in test modal. I want to read it as a list in UI side. I can't quite figure it out how?

class TestModal {
 final String id;
 final String venueName;
 final String eventName;
 List<ArtistModal> artistModal = <ArtistModal>[];

TestModal({
required this.venueName,
required this.id,
required this.eventName,
required this.artistModal,
});

factory TestModal.fromJson(Map<String, dynamic> json) {
return TestModal(
    venueName: json['venueName'] ?? '',
    eventName: json['eventName'] ?? '',
    artistModal: List.from(json['artistModal'] ?? ''),
    id: json['id'] ?? '');
}

Map<String, dynamic> toMap() {
return {
  'venueName': venueName,
  'eventName': eventName,
  'artistModal': artistModal,
  'id': id,
  };
 }
}