Closed
Description
Dart's Map Patterns Deconstructing a Non-Existent Key throws a "Pattern matching error", but I want the variable to be null, Does Dart's syntax support this? How can I do that?
Practical scenario: When I'm Deconstructing Json, I'm not sure if a key exists in the Json or not, and if it doesn't, it will cause the problem.
void main() {
final userInfo = {
"name": "Jack",
"age": 18
};
// Here throws a Pattern matching error, but my expectation is that the gender variable is null, so how do I do this?
final {"gender": gender as String?} = userInfo;
print(gender);
}