when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String name,
    3. String email,
    4. bool emailVerified,
    5. String? image,
    6. DateTime? createdAt,
    7. DateTime? updatedAt,
    8. bool twoFactorEnabled,
    9. String? username,
    10. String? displayUsername,
    11. bool isAnonymous,
    12. String? phoneNumber,
    13. bool phoneNumberVerified,
    14. String? role,
    15. bool banned,
    16. String? banReason,
    17. DateTime? banExpires,
    )
)

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 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():
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 _:
  throw StateError('Unexpected subclass');

}
}