I couldn't find a way to safely unwrap an optional variable as we do in swift
var myString: String?
if let myString = myString {
print(myString) // myString is a string
}
or in Kotlin
var myString: String?
if (myString != null) {
print(myString) // myString is not null
}
// or
myString?.let {
print(it) // myString is not null
}
In Dart I'm having to do the following, which doesn't look good:
String? myString;
if (myString != null) {
print(myString); // myString still an optional
print(myString!); // myString is now a String! (because of the force unwrap)
}
Is there a way to safely unwrap in a clean way like other null-safety languages? Or we have to always force unwrap variables after a null-check?