8

I'm trying to add persistence to my app using firestore. It seems ace, but I've hit a bump in the road, and googling seems to be failing me. I think this may be more of a dart question than firestore, so please edit as you see fit!

Essentially I have a situation similar the following:

class attributes(){
  double xpos, ypos;
  String id;
}

class item(){
  String name;
  int price;
  List<attributes> attributeHistory;
  Map<String, dynamic> toMap(){
    Map<String, dynamic> returnMap = new Map();
    returnMap['name'] = name;
    returnMap['price'] = price;
    returnMap['attributeHistory'] = //what goes here??;
    }
}

So... What goes there? I've written a .toMap function for attributes, but I don't know where that gets me!

Any ideas?

1 Answer 1

14

Create a List of Map<String,dynamic>

returnMap['attributeHistory'] = attributeHistory.map((attribute) {
  Map<String,dynamic> attributeMap = new Map<String,dynamic>();
  attributeMap["id"] = attribute.id;
  // same for xpos and ypos
  return attributeMap;
}).toList();
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Brilliant answer. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.