Skip to content

Instantly share code, notes, and snippets.

@samiy-xx
Created June 13, 2013 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samiy-xx/5772273 to your computer and use it in GitHub Desktop.
Save samiy-xx/5772273 to your computer and use it in GitHub Desktop.
quickie
import 'dart:json' as json;
class CartItem {
int id;
String name;
String category;
CartItem(this.id, this.name, this.category);
Map toJson() {
return {
'id': id,
'name': name,
'category': category
}
}
static CartItem fromMap(Map m) {
return new CartItem(m['id'], m['name'], m['category']);
}
}
List<CartItem> items = new List<CartItem>();
items.add(new CartItem(0, "Banana", "food"));
items.where((CartItem item) => item.category == "food").forEach((CartItem item) => print(item.name));
//stringify object:
json.stringify(yourObject.toJson());
// parse object
CartItem item = CartItem.fromMap(json.parse(STRING_JSON_FROM_SERVER));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment