Skip to content

Instantly share code, notes, and snippets.

@jbarguil
Last active August 23, 2021 15:50
Show Gist options
  • Save jbarguil/2fff205fd9a781b9698462ca822f19bd to your computer and use it in GitHub Desktop.
Save jbarguil/2fff205fd9a781b9698462ca822f19bd to your computer and use it in GitHub Desktop.
Dart test
class A {
String method() => "value";
}
class B {
A? field;
B([this.field]); // Using [] to denote optional parameter.
Map<String, String?> toJson() {
return <String, String?> {
'field': field?.method(), // If field is null, this returns null.
};
}
}
main() {
var b1 = B();
var b2 = B(A());
print(b1.toJson());
print(b2.toJson());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment