whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? $default(
- String id,
- String name,
- String email,
- bool emailVerified,
- String? image,
- DateTime? createdAt,
- DateTime? updatedAt,
- bool twoFactorEnabled,
- String? username,
- String? displayUsername,
- bool isAnonymous,
- String? phoneNumber,
- bool phoneNumberVerified,
- String? role,
- bool banned,
- String? banReason,
- DateTime? banExpires,
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( String id, String name, String email, bool emailVerified, String? image, DateTime? createdAt, DateTime? updatedAt, bool twoFactorEnabled, String? username, String? displayUsername, bool isAnonymous, String? phoneNumber, bool phoneNumberVerified, String? role, bool banned, String? banReason, DateTime? banExpires)? $default,) {final _that = this;
switch (_that) {
case _User() when $default != null:
return $default(_that.id,_that.name,_that.email,_that.emailVerified,_that.image,_that.createdAt,_that.updatedAt,_that.twoFactorEnabled,_that.username,_that.displayUsername,_that.isAnonymous,_that.phoneNumber,_that.phoneNumberVerified,_that.role,_that.banned,_that.banReason,_that.banExpires);case _:
return null;
}
}