whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? $default(
- int id,
- int userId,
- String name,
- String status,
- List<
String> ipWhitelist, - List<
String> ipBlacklist, - Sub2ApiDecimal quota,
- Sub2ApiDecimal quotaUsed,
- int currentConcurrency,
- Sub2ApiKeyUsageWindow fiveHourWindow,
- Sub2ApiKeyUsageWindow oneDayWindow,
- Sub2ApiKeyUsageWindow sevenDayWindow,
- DateTime createdAt,
- DateTime updatedAt,
- int? groupId,
- DateTime? expiresAt,
- DateTime? lastUsedAt,
- String? lastUsedIp,
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,
int userId,
String name,
String status,
List<String> ipWhitelist,
List<String> ipBlacklist,
Sub2ApiDecimal quota,
Sub2ApiDecimal quotaUsed,
int currentConcurrency,
Sub2ApiKeyUsageWindow fiveHourWindow,
Sub2ApiKeyUsageWindow oneDayWindow,
Sub2ApiKeyUsageWindow sevenDayWindow,
DateTime createdAt,
DateTime updatedAt,
int? groupId,
DateTime? expiresAt,
DateTime? lastUsedAt,
String? lastUsedIp,
)?
$default,
) {
final _that = this;
switch (_that) {
case _Sub2ApiKeySummary() when $default != null:
return $default(
_that.id,
_that.userId,
_that.name,
_that.status,
_that.ipWhitelist,
_that.ipBlacklist,
_that.quota,
_that.quotaUsed,
_that.currentConcurrency,
_that.fiveHourWindow,
_that.oneDayWindow,
_that.sevenDayWindow,
_that.createdAt,
_that.updatedAt,
_that.groupId,
_that.expiresAt,
_that.lastUsedAt,
_that.lastUsedIp,
);
case _:
return null;
}
}