Skip to content

Instantly share code, notes, and snippets.

@shumiyao
Created February 14, 2021 20:59
Show Gist options
  • Save shumiyao/e2a6aab2829eb044c782df330ec6b25c to your computer and use it in GitHub Desktop.
Save shumiyao/e2a6aab2829eb044c782df330ec6b25c to your computer and use it in GitHub Desktop.
Dart: add value to Map conditionally by using spread
void main() {
bool test = false;
Map<String, String> myMapA = {
"a": "1",
"b": "2",
... test == true ? {"c":"3"} : {}
};
Map<String, String> myMapB = {
"a": "1",
"b": "2",
... test == false ? {"c":"3"} : {}
};
print(myMapA);
print(myMapB);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment