Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
delay opened this issue Aug 23, 2020 · 0 comments
Open

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

delay opened this issue Aug 23, 2020 · 0 comments

Comments

@delay
Copy link

delay commented Aug 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant