when<TResult extends Object?> method Null safety

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
      ),
    1. {required TResult success(
      1. T value
      ),
    2. required TResult fail(
      1. KakaoSdkError error
      )}
    )

    Implementation

    @optionalTypeArgs
    TResult when<TResult extends Object?>(TResult Function() $default,
        {required TResult Function(T value) success,
        required TResult Function(KakaoSdkError error) fail}) {
      assert($default != null);
      assert(success != null);
      assert(fail != null);
      if (isValue) {
        return success(asValue!.value);
      } else if (isError) {
        return fail(asError!.error as KakaoSdkError);
      }
      return $default();
    }