Last active
September 13, 2022 16:55
-
-
Save j05u3/4a2f1557e83859d3ab536abc2593e820 to your computer and use it in GitHub Desktop.
testing in-place assignment and return
This file contains hidden or 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
getMe() { | |
print("get me! heavy computation here or maybe set up a reusable API client (or something else) here"); | |
return 3; | |
} | |
class X { | |
int? _ethersProvider; // this variable is visible only in this file, so basically this works as a "private" variable (as there is no "private" in dart) | |
int? get ethersProvider => _ethersProvider ?? (_ethersProvider = getMe()); | |
} | |
void main() { | |
final x = new X(); | |
print(x.ethersProvider); | |
print(x.ethersProvider); | |
// will print "get me!" only once | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment