whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. double? width,
    2. double? height,
    3. double? size,
    4. @igFreezedJson BoxFit? fit,
    5. @igFreezedJson BorderRadius? borderRadius,
    6. @igFreezedJson BoxShape? shape,
    7. bool enableMemoryCache,
    8. String? heroTag,
    9. bool isSelected,
    10. @igFreezedJson Widget? errorWidget,
    11. @igFreezedJson VoidCallback? onTap,
    12. @igFreezedJson Color? color,
    13. bool clearMemoryCacheIfFailed,
    14. bool clearMemoryCacheWhenDispose,
    15. bool gaplessPlayback,
    16. @igFreezedJson BlendMode? colorBlendMode,
    17. FilterQuality filterQuality,
    18. double? scale,
    19. Map<String, String> headers,
    20. bool cache,
    21. int retries,
    22. @igFreezedJson Duration? timeLimit,
    23. @igFreezedJson Duration timeRetry,
    24. @igFreezedJson CancellationToken? cancelToken,
    25. String? cacheKey,
    26. bool printError,
    27. bool cacheRawData,
    28. String? imageCacheName,
    29. @igFreezedJson Duration? cacheMaxAge,
    30. int? cacheWidth,
    31. int? cacheHeight,
    32. double? compressionRatio,
    33. int? maxBytes,
    34. String? package,
    35. @igFreezedJson AssetBundle? bundle,
    36. @Doc(message: '自定义完成小部件') @igFreezedJson CustomCompletedWidget? customCompletedWidget,
    37. @igFreezedJson Widget? customLoadingWidget,
    38. @igFreezedJson InitEditorConfigHandler? initEditorConfigHandler,
    39. @igFreezedJson Key? extendedImageEditorKey,
    40. @igFreezedJson ExtendedImageMode? mode,
    )?
)

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(
          double? width,
          double? height,
          double? size,
          @igFreezedJson BoxFit? fit,
          @igFreezedJson BorderRadius? borderRadius,
          @igFreezedJson BoxShape? shape,
          bool enableMemoryCache,
          String? heroTag,
          bool isSelected,
          @igFreezedJson Widget? errorWidget,
          @igFreezedJson VoidCallback? onTap,
          @igFreezedJson Color? color,
          bool clearMemoryCacheIfFailed,
          bool clearMemoryCacheWhenDispose,
          bool gaplessPlayback,
          @igFreezedJson BlendMode? colorBlendMode,
          FilterQuality filterQuality,
          double? scale,
          Map<String, String> headers,
          bool cache,
          int retries,
          @igFreezedJson Duration? timeLimit,
          @igFreezedJson Duration timeRetry,
          @igFreezedJson CancellationToken? cancelToken,
          String? cacheKey,
          bool printError,
          bool cacheRawData,
          String? imageCacheName,
          @igFreezedJson Duration? cacheMaxAge,
          int? cacheWidth,
          int? cacheHeight,
          double? compressionRatio,
          int? maxBytes,
          String? package,
          @igFreezedJson AssetBundle? bundle,
          @Doc(message: '自定义完成小部件')
          @igFreezedJson
          CustomCompletedWidget? customCompletedWidget,
          @igFreezedJson Widget? customLoadingWidget,
          @igFreezedJson InitEditorConfigHandler? initEditorConfigHandler,
          @igFreezedJson Key? extendedImageEditorKey,
          @igFreezedJson ExtendedImageMode? mode)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _ImageParams() when $default != null:
      return $default(
          _that.width,
          _that.height,
          _that.size,
          _that.fit,
          _that.borderRadius,
          _that.shape,
          _that.enableMemoryCache,
          _that.heroTag,
          _that.isSelected,
          _that.errorWidget,
          _that.onTap,
          _that.color,
          _that.clearMemoryCacheIfFailed,
          _that.clearMemoryCacheWhenDispose,
          _that.gaplessPlayback,
          _that.colorBlendMode,
          _that.filterQuality,
          _that.scale,
          _that.headers,
          _that.cache,
          _that.retries,
          _that.timeLimit,
          _that.timeRetry,
          _that.cancelToken,
          _that.cacheKey,
          _that.printError,
          _that.cacheRawData,
          _that.imageCacheName,
          _that.cacheMaxAge,
          _that.cacheWidth,
          _that.cacheHeight,
          _that.compressionRatio,
          _that.maxBytes,
          _that.package,
          _that.bundle,
          _that.customCompletedWidget,
          _that.customLoadingWidget,
          _that.initEditorConfigHandler,
          _that.extendedImageEditorKey,
          _that.mode);
    case _:
      return null;
  }
}