whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String? uid,
    2. String? givenName,
    3. String? middleName,
    4. String? familyName,
    5. String? name,
    6. String? nickname,
    7. String? birthdate,
    8. String? profileURL,
    9. String? picture,
    10. String? externalId,
    11. List<String>? authTypes,
    12. LoginSummary? loginSummary,
    13. String? username,
    14. String? gender,
    15. String? email,
    16. bool? emailVerified,
    17. Emails? emails,
    18. String? phoneNumber,
    19. bool? phoneNumberVerified,
    20. List<ProfileAddress>? addresses,
    21. String? locale,
    22. String? bio,
    23. Map<String, Object?>? customFields,
    24. Map<String, Consent>? consents,
    25. String? createdAt,
    26. String? updatedAt,
    27. bool? liteOnly,
    28. String? company,
    )?
)

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(
          String? uid,
          String? givenName,
          String? middleName,
          String? familyName,
          String? name,
          String? nickname,
          String? birthdate,
          String? profileURL,
          String? picture,
          String? externalId,
          List<String>? authTypes,
          LoginSummary? loginSummary,
          String? username,
          String? gender,
          String? email,
          bool? emailVerified,
          Emails? emails,
          String? phoneNumber,
          bool? phoneNumberVerified,
          List<ProfileAddress>? addresses,
          String? locale,
          String? bio,
          Map<String, Object?>? customFields,
          Map<String, Consent>? consents,
          String? createdAt,
          String? updatedAt,
          bool? liteOnly,
          String? company)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _Profile() when $default != null:
      return $default(
          _that.uid,
          _that.givenName,
          _that.middleName,
          _that.familyName,
          _that.name,
          _that.nickname,
          _that.birthdate,
          _that.profileURL,
          _that.picture,
          _that.externalId,
          _that.authTypes,
          _that.loginSummary,
          _that.username,
          _that.gender,
          _that.email,
          _that.emailVerified,
          _that.emails,
          _that.phoneNumber,
          _that.phoneNumberVerified,
          _that.addresses,
          _that.locale,
          _that.bio,
          _that.customFields,
          _that.consents,
          _that.createdAt,
          _that.updatedAt,
          _that.liteOnly,
          _that.company);
    case _:
      return null;
  }
}