when<TResult extends Object?> method
- @optionalTypeArgs
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 $type, String did, int accountReportCount, int recordReportCount, int reportedAccountCount, int reportedRecordCount, int takendownAccountCount, int takendownRecordCount, int labeledAccountCount, int labeledRecordCount, Map<String, dynamic>? $unknown) $default,) {final _that = this;
switch (_that) {
case _ReporterStats():
return $default(_that.$type,_that.did,_that.accountReportCount,_that.recordReportCount,_that.reportedAccountCount,_that.reportedRecordCount,_that.takendownAccountCount,_that.takendownRecordCount,_that.labeledAccountCount,_that.labeledRecordCount,_that.$unknown);case _:
throw StateError('Unexpected subclass');
}
}