isEmpty method

bool isEmpty()

If a value is not present, returns true, otherwise false.

Returns true if a value is not present, otherwise false.

Example

Optional<String> name = Optional.of("Diana");
Optional<String> empty = Optional.empty();

print(name.isEmpty()); // false
print(empty.isEmpty()); // true

// Useful for guard clauses
if (someOptional.isEmpty()) {
  return "No data available";
}

Implementation

bool isEmpty() {
  return _value == null;
}