Last active
August 23, 2021 15:50
-
-
Save jbarguil/2fff205fd9a781b9698462ca822f19bd to your computer and use it in GitHub Desktop.
Dart test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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