when<TResult extends Object?> method
- TResult $default(
- String id,
- String userId,
- String topicId,
- String? chunkId,
- String cardType,
- String front,
- String back,
- double easinessFactor,
- int intervalDays,
- int repetitions,
- DateTime nextReviewAt,
- DateTime? lastReviewAt,
- int? lastQuality,
- double? stability,
- double? difficulty,
- String state,
- double? lastElapsedDays,
- int? scheduledDays,
- String algorithm,
- Map<
String, dynamic> ? cardData,
A switch-like method, using callbacks.
As opposed to map, this offers destructuring.
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case Subclass2(:final field2):
return ...;
}
Implementation
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String userId, String topicId, String? chunkId, String cardType, String front, String back, double easinessFactor, int intervalDays, int repetitions, DateTime nextReviewAt, DateTime? lastReviewAt, int? lastQuality, double? stability, double? difficulty, String state, double? lastElapsedDays, int? scheduledDays, String algorithm, Map<String, dynamic>? cardData) $default,) {final _that = this;
switch (_that) {
case _ReviewCard():
return $default(_that.id,_that.userId,_that.topicId,_that.chunkId,_that.cardType,_that.front,_that.back,_that.easinessFactor,_that.intervalDays,_that.repetitions,_that.nextReviewAt,_that.lastReviewAt,_that.lastQuality,_that.stability,_that.difficulty,_that.state,_that.lastElapsedDays,_that.scheduledDays,_that.algorithm,_that.cardData);case _:
throw StateError('Unexpected subclass');
}
}