Reputation: 3844
I have problems with Dart null safety.
Even when I explicitly check for nulls, it still complains
The exclamation mark is solving that
but it's pretty ugly and cumbersome.
Is there a way to make it smarter and nicer? Like e.g. header?.let{ it.toUpperCase() }
in Kotlin?
Upvotes: 1
Views: 193
Reputation: 503
I suppose that header has a type of String?. It seems that variables used in logical expressions must be part of the local scope of the current context. In your example, passing down header as a String? typed argument allow your to access String methods if its value is not null.
Widget _buildHeader(String? header) {
if (header != null) {
return Text(h.toUpperCase());
}
return Container();
}
Upvotes: 2