takeIf method

T? takeIf(
  1. bool predicate(
    1. T it
    )
)

Returns value if it satisfies the predicate, otherwise null Usage: number.takeIf((it) => it > 0)

Implementation

T? takeIf(bool Function(T it) predicate) {
  final self = this;
  if (self != null) {
    return predicate(self) ? this : null;
  }
  return null;
}