when<TResult extends Object?> method
- TResult $default(
- String id,
- String userId,
- String? topicId,
- String? domainId,
- String sessionType,
- DateTime startedAt,
- DateTime? endedAt,
- int? durationMinutes,
- String? kolbPhase,
- bool reflectionCompleted,
- String? reflectionText,
- int? confidenceBefore,
- int? confidenceAfter,
- List<
String> ? keyTakeaways, - bool isValidation,
- String? validationTarget,
- String? validationResult,
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? domainId, String sessionType, DateTime startedAt, DateTime? endedAt, int? durationMinutes, String? kolbPhase, bool reflectionCompleted, String? reflectionText, int? confidenceBefore, int? confidenceAfter, List<String>? keyTakeaways, bool isValidation, String? validationTarget, String? validationResult) $default,) {final _that = this;
switch (_that) {
case _LearningSessionModel():
return $default(_that.id,_that.userId,_that.topicId,_that.domainId,_that.sessionType,_that.startedAt,_that.endedAt,_that.durationMinutes,_that.kolbPhase,_that.reflectionCompleted,_that.reflectionText,_that.confidenceBefore,_that.confidenceAfter,_that.keyTakeaways,_that.isValidation,_that.validationTarget,_that.validationResult);case _:
throw StateError('Unexpected subclass');
}
}