In Swift, there's a simple language feature to chain unwrapping and checking for non null like this:
if let data = functionReturningNullableNumber(), data != 0 { processNum(data) }
if let data = functionReturningNullableString(), data != "" { processStr(data) }
In Flutter, currently I have to do this:
var dataNum = functionReturningNullableNumber();
if (dataNum != null && dataNum != 0) { processNum(dataNum); }
var dataStr = functionReturningNullableString();
if (dataStr != null && dataStr != "") { processStr(dataStr); }
Is it possible to create something similar to the Swift above? Especially the part where I can assign a temporary variable name that will disappear outside of the if
scope, so I can reuse the variable name.
Of course I can do this:
if (functionReturningNullableNumber() != null && functionReturningNullableNumber() != 0) { process(functionReturningNullableNumber()); }
But this isn't what I'm searching for.