toWidget method

Widget toWidget({
  1. required Widget onResult(
    1. TResult lastResult,
    2. TParam? param
    ),
  2. Widget whileExecuting(
    1. TResult lastResult,
    2. TParam? param
    )?,
  3. Widget onError(
    1. Object? error,
    2. TParam? param
    )?,
})

Returns a the result of one of three builders depending on the current state of the Command. This function won't trigger a rebuild if the command changes states so it should be used together with get_it_mixin, provider, flutter_hooks and the like.

Implementation

Widget toWidget({
  required Widget Function(TResult lastResult, TParam? param) onResult,
  Widget Function(TResult lastResult, TParam? param)? whileExecuting,
  Widget Function(Object? error, TParam? param)? onError,
}) {
  if (_commandResult.value.hasError) {
    return onError?.call(
          _commandResult.value.error,
          _commandResult.value.paramData,
        ) ??
        const SizedBox();
  }
  if (isExecuting.value) {
    return whileExecuting?.call(value, _commandResult.value.paramData) ??
        const SizedBox();
  }
  return onResult(value, _commandResult.value.paramData);
}