Option<MAYBE> class
Represents a nullable value. Ensures safe handling of nullable values by enforcing the explicit handling of both states of the value. Can have the state of something (some) or nothing (none).
Constructors
- Option.none()
-
Returns a const Option where the inner value is always null.
factory
- Option.of(MAYBE? maybeValue)
-
Creates an Option from a nullable
maybeValue
.factory
Properties
Methods
-
get(
MAYBE fallback) → MAYBE -
Gets the inner value if not null or
fallback
otherwise. -
getOr(
MAYBE fallback()) → MAYBE -
Gets the inner value if not null or result of
fallback
otherwise. -
getOrAsync(
Future< MAYBE> fallback()) → Future<MAYBE> - Async version of Option.getOr.
-
getUnsafe(
) → MAYBE? - Returns the inner value as nullable. Only use this if necessary.
-
ifNone<
RETURN> (RETURN onNone()) → Option< RETURN> -
Calls
onNone
ifthis.isNone
and returns its value in a new Option. -
ifNoneAsync<
RETURN> (Future< RETURN> onNone()) → Future<Option< RETURN> > - Async version of Option.ifNone.
-
ifSome<
RETURN> (RETURN onSome(MAYBE some)) → Option< RETURN> -
Calls
onSome
ifthis.isSome
and returns its value in a new Option. -
ifSomeAsync<
RETURN> (Future< RETURN> onSome(MAYBE some)) → Future<Option< RETURN> > - Async version of Option.ifSome.
-
match<
RETURN> ({required RETURN onSome(MAYBE some), required RETURN onNone()}) → RETURN - Calls the matching function and returns its value.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited