Skip to content

SetList option gives me an error when writing a list of maps. #70

@delay

Description

@delay

Thanks for this great package! I am having one problem. I am getting an error when using setList to write a list of maps.

When I try and write to firestore and update a document with the setList option it gives me an error.

Unsupported operation: Value of type minified:b1 is not supported by Firestore.

I have a model that has a list of activities (a log of what the property has done)

class Property {
  String id;
  String owner;
  String email;
  List<Invoice> invoices;
  List<LogModel> activity;

  Property(
      {this.id,
      this.owner,
      this.email,
      this.activity});

  factory Property.fromMap(Map data) {
    return Property(
      id: data['id'],
      owner: data['owner'] ?? '',
      email: data['email'] ?? '',
      activity: (data['activity'] as List ?? [])
          .map((v) => LogModel.fromMap(v))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "owner": owner,
        "email": email,
        "activity": List<dynamic>.from(activity.map((x) => x.toJson())),
      };
}

class LogModel {
  String id;
  String user;
  String message;
  int date;

  LogModel({this.id, this.user, this.message, this.date});

  LogModel.fromMap(Map data) {
    id = data['id'];
    user = data['user'] ?? '';
    message = data['message'] ?? '';
    date = data['date'];
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "user": user,
        "message": message,
        "date": date,
      };
}
 UpdateData propertyData = UpdateData();
  propertyData.setString("email", property.email);
  propertyData.setList("activity", property.activity);

  final ref = app.firestore().document('/properties/${property.id}');

  await ref.updateData(propertyData);

Thanks so much for any advice on how to handle this situation when it is a list of Maps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions