whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. String name,
    3. String homepage,
    4. @JsonKey.new(name: 'image_id') String imageId,
    5. int order,
    6. @JsonKey.new(name: 'android_app_id') String? androidAppId,
    7. @JsonKey.new(name: 'mobile_link') String? mobileLink,
    8. @JsonKey.new(name: 'desktop_link') String? desktopLink,
    9. @JsonKey.new(name: 'link_mode') String? linkMode,
    10. @JsonKey.new(name: 'webapp_link') String? webappLink,
    11. @JsonKey.new(name: 'app_store') String? appStore,
    12. @JsonKey.new(name: 'play_store') String? playStore,
    13. String? rdns,
    14. @JsonKey.new(name: 'chrome_store') String? chromeStore,
    15. List<Injected>? injected,
    16. List<String>? chains,
    17. List<String>? categories,
    18. String? description,
    19. @JsonKey.new(name: 'badge_type') String? badgeType,
    20. @JsonKey.new(name: 'supports_wc') bool? supportsWc,
    21. @JsonKey.new(name: 'is_top_wallet') bool? isTopWallet,
    )?
)

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 id,  String name,  String homepage, @JsonKey(name: 'image_id')  String imageId,  int order, @JsonKey(name: 'android_app_id')  String? androidAppId, @JsonKey(name: 'mobile_link')  String? mobileLink, @JsonKey(name: 'desktop_link')  String? desktopLink, @JsonKey(name: 'link_mode')  String? linkMode, @JsonKey(name: 'webapp_link')  String? webappLink, @JsonKey(name: 'app_store')  String? appStore, @JsonKey(name: 'play_store')  String? playStore,  String? rdns, @JsonKey(name: 'chrome_store')  String? chromeStore,  List<Injected>? injected,  List<String>? chains,  List<String>? categories,  String? description, @JsonKey(name: 'badge_type')  String? badgeType, @JsonKey(name: 'supports_wc')  bool? supportsWc, @JsonKey(name: 'is_top_wallet')  bool? isTopWallet)?  $default,) {final _that = this;
switch (_that) {
case _AppKitModalWalletListing() when $default != null:
return $default(_that.id,_that.name,_that.homepage,_that.imageId,_that.order,_that.androidAppId,_that.mobileLink,_that.desktopLink,_that.linkMode,_that.webappLink,_that.appStore,_that.playStore,_that.rdns,_that.chromeStore,_that.injected,_that.chains,_that.categories,_that.description,_that.badgeType,_that.supportsWc,_that.isTopWallet);case _:
  return null;

}
}