when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int? id,
    2. String? login,
    3. String? name,
    4. String? company,
    5. String? blog,
    6. String? bio,
    7. String? location,
    8. String? email,
    9. String? xUsername,
    10. String? nodeId,
    11. String? type,
    12. bool siteAdmin,
    13. bool hirable,
    14. int publicReposCount,
    15. int publicGistsCount,
    16. int followersCount,
    17. int followingCount,
    18. ModelImageUri? avatarUrl,
    19. String? gravatarId,
    20. ModelUri? htmlUrl,
    21. ModelUri? userUrl,
    22. ModelUri? eventsUrl,
    23. ModelUri? followersUrl,
    24. ModelUri? followingUrl,
    25. ModelUri? gistsUrl,
    26. ModelUri? organizationsUrl,
    27. ModelUri? receivedEventsUrl,
    28. ModelUri? reposUrl,
    29. ModelUri? starredUrl,
    30. ModelUri? subscriptionsUrl,
    31. ModelTimestamp? starredAt,
    32. ModelTimestamp createdAt,
    33. ModelTimestamp updatedAt,
    )
)

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(
          int? id,
          String? login,
          String? name,
          String? company,
          String? blog,
          String? bio,
          String? location,
          String? email,
          String? xUsername,
          String? nodeId,
          String? type,
          bool siteAdmin,
          bool hirable,
          int publicReposCount,
          int publicGistsCount,
          int followersCount,
          int followingCount,
          ModelImageUri? avatarUrl,
          String? gravatarId,
          ModelUri? htmlUrl,
          ModelUri? userUrl,
          ModelUri? eventsUrl,
          ModelUri? followersUrl,
          ModelUri? followingUrl,
          ModelUri? gistsUrl,
          ModelUri? organizationsUrl,
          ModelUri? receivedEventsUrl,
          ModelUri? reposUrl,
          ModelUri? starredUrl,
          ModelUri? subscriptionsUrl,
          ModelTimestamp? starredAt,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubUserModel():
      return $default(
          _that.id,
          _that.login,
          _that.name,
          _that.company,
          _that.blog,
          _that.bio,
          _that.location,
          _that.email,
          _that.xUsername,
          _that.nodeId,
          _that.type,
          _that.siteAdmin,
          _that.hirable,
          _that.publicReposCount,
          _that.publicGistsCount,
          _that.followersCount,
          _that.followingCount,
          _that.avatarUrl,
          _that.gravatarId,
          _that.htmlUrl,
          _that.userUrl,
          _that.eventsUrl,
          _that.followersUrl,
          _that.followingUrl,
          _that.gistsUrl,
          _that.organizationsUrl,
          _that.receivedEventsUrl,
          _that.reposUrl,
          _that.starredUrl,
          _that.subscriptionsUrl,
          _that.starredAt,
          _that.createdAt,
          _that.updatedAt);
    case _:
      throw StateError('Unexpected subclass');
  }
}