emptyCase method
void
emptyCase({
- void onEmpty()?,
- void onNotEmpty()?,
- void onNotEmptyOrNull()?,
Handles different cases for a nullable string.
Depending on the state of the source, different callbacks are invoked:
- If the source is not
nulland is empty,onEmptyis called. - If the source is not
nulland is not empty,onNotEmptyis called. - If the source is
null,onNotEmptyOrNullis called.
Parameters:
onEmpty: Callback to execute when the source is notnulland empty.onNotEmpty: Callback to execute when the source is notnulland not empty.onNotEmptyOrNull: Callback to execute when the source isnullor not empty.
Example:
'example'.be.emptyCase(
onEmpty: () => print('The string is empty'),
onNotEmpty: () => print('The string is not empty'),
onNotEmptyOrNull: () => print('The string is not empty or null'),
);
Implementation
void emptyCase({
void Function()? onEmpty,
void Function()? onNotEmpty,
void Function()? onNotEmptyOrNull,
}) {
final value = source;
if (value != null) {
if (value.isEmpty) {
onEmpty?.call();
} else {
onNotEmpty?.call();
}
} else {
onNotEmptyOrNull?.call();
}
}