when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String placeholder,
    2. String title,
    3. String okBtnText,
    4. String cancelBtnText,
    5. @igFreezedJson bool disableOkButton(
      1. int value
      )?,
    6. @igFreezedJson String? errorMessage(
      1. int value
      )?,
    7. @igFreezedJson TextStyle? okButtonTextStyle,
    8. @igFreezedJson TextStyle? cancelButtonTextStyle,
    )
)

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 placeholder,
          String title,
          String okBtnText,
          String cancelBtnText,
          @igFreezedJson bool Function(int value)? disableOkButton,
          @igFreezedJson String? Function(int value)? errorMessage,
          @igFreezedJson TextStyle? okButtonTextStyle,
          @igFreezedJson TextStyle? cancelButtonTextStyle)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _AskIntDialogParams():
      return $default(
          _that.placeholder,
          _that.title,
          _that.okBtnText,
          _that.cancelBtnText,
          _that.disableOkButton,
          _that.errorMessage,
          _that.okButtonTextStyle,
          _that.cancelButtonTextStyle);
  }
}