Skip to content

Instantly share code, notes, and snippets.

@onikazu
Created February 8, 2020 13:31
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 onikazu/0a17acd65b073021281c3a1a19b28de2 to your computer and use it in GitHub Desktop.
Save onikazu/0a17acd65b073021281c3a1a19b28de2 to your computer and use it in GitHub Desktop.
class Record {
final String name;
final int votes;
final DocumentReference reference;
// for null safety
// Initializer Lists constructor
// option arguments
// https://makicamel.hatenablog.com/entry/2019/03/14/213933
Record.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map["name"] != null),
assert(map["votes"] != null),
name = map["name"],
votes = map["votes"];
// Initializer Lists constructor
Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);
@override
String toString() => "Record<$name: $votes>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment