whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>(
- TResult? $default(
- int? id,
- String? name,
- String? login,
- String? company,
- String? blog,
- String? location,
- String? email,
- int publicReposCount,
- int publicGistsCount,
- int followersCount,
- int followingCount,
- ModelUri? htmlUrl,
- ModelImageUri? avatarUrl,
- GithubOrganizationType type,
- ModelTimestamp createdAt,
- ModelTimestamp updatedAt,
A variant of when
that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function(
int? id,
String? name,
String? login,
String? company,
String? blog,
String? location,
String? email,
int publicReposCount,
int publicGistsCount,
int followersCount,
int followingCount,
ModelUri? htmlUrl,
ModelImageUri? avatarUrl,
GithubOrganizationType type,
ModelTimestamp createdAt,
ModelTimestamp updatedAt)?
$default,
) {
final _that = this;
switch (_that) {
case _GithubOrganizationModel() when $default != null:
return $default(
_that.id,
_that.name,
_that.login,
_that.company,
_that.blog,
_that.location,
_that.email,
_that.publicReposCount,
_that.publicGistsCount,
_that.followersCount,
_that.followingCount,
_that.htmlUrl,
_that.avatarUrl,
_that.type,
_that.createdAt,
_that.updatedAt);
case _:
return null;
}
}