Skip to content

Instantly share code, notes, and snippets.

@j05u3
Last active September 13, 2022 16:55
Show Gist options
  • Save j05u3/4a2f1557e83859d3ab536abc2593e820 to your computer and use it in GitHub Desktop.
Save j05u3/4a2f1557e83859d3ab536abc2593e820 to your computer and use it in GitHub Desktop.
testing in-place assignment and return
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