1 factory SuggestSessionResult.fromJson(Map<String, dynamic> json) {
2 final String? error = json['error'];
3 final List<Map<String, dynamic>>? items = json['items'];
4 return SuggestSessionResult(
5 items
6 ?.map((it)=>SuggestItem.fromJson(it))
7 .toList(),
8 error
);
}
Hello! As you can see, I've not used null-aware operator in line 7 and that's ok for compiler. Moreover, when I use it, the analyzer says the receiver can't be null. Why so?
In Dart 2.12,
?.was made short-circuiting.From the Understanding null safety document:
In your case,
.map(), if called, cannot returnnull(becauseIterable.mapdoes not return a nullable type). Therefore.toList()either will never be called (because.map()was not called earlier in the method chain) or will be guaranteed to be called on a non-null value.