match<R> method

R? match<R>({
  1. R fulfilled(
    1. T
    )?,
  2. R rejected(
    1. dynamic
    )?,
  3. R pending()?,
})

Maps the current state of this.

Returns null if a handler for the current state is not provided.

Implementation

R? match<R>({
  R Function(T)? fulfilled,
  // ignore:avoid_annotating_with_dynamic
  R Function(dynamic)? rejected,
  R Function()? pending,
}) {
  final status = this.status;

  if (status == FutureStatus.fulfilled) {
    return fulfilled == null ? null : fulfilled(result as T);
  } else if (status == FutureStatus.rejected) {
    return rejected == null ? null : rejected(result);
  }
  return pending == null ? null : pending();
}