onlyIf method

T? onlyIf(
  1. bool? condition
)

Returns this value only if condition is true.

Otherwise, returns null.

Example:

token.onlyIf(isLoggedIn);

Implementation

T? onlyIf(bool? condition) {
  if (condition == true) return this;
  return null;
}