mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? done(
    1. PickerLoadStatusDone value
    )?,
  2. TResult? error(
    1. PickerLoadStatusError value
    )?,
  3. TResult? progress(
    1. PickerLoadStatusProgress value
    )?,
})

A variant of map that fallback to returning null.

It is equivalent to doing:

switch (sealedClass) {
  case final Subclass value:
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( PickerLoadStatusDone value)?  done,TResult? Function( PickerLoadStatusError value)?  error,TResult? Function( PickerLoadStatusProgress value)?  progress,}){
final _that = this;
switch (_that) {
case PickerLoadStatusDone() when done != null:
return done(_that);case PickerLoadStatusError() when error != null:
return error(_that);case PickerLoadStatusProgress() when progress != null:
return progress(_that);case _:
  return null;

}
}