createSync<TParam, TResult> static method

Command<TParam, TResult> createSync<TParam, TResult>(
  1. TResult func(
    1. TParam x
    ),
  2. TResult initialValue, {
  3. ValueListenable<bool>? restriction,
  4. bool includeLastResultInCommandResults = false,
  5. bool? catchAlways,
  6. String? debugName,
})

Creates a Command for a synchronous handler function with parameter that returns a value func: handler function initialValue sets the .value of the Command. restriction : ValueListenable<bool> that can be used to enable/disable the command based on some other state change. If omitted the command can be executed always except it's already executing includeLastResultInCommandResults will include the value of the last successful execution in all CommandResult values unless there is no result. This can be handy if you always want to be able to display something even when you got an error. As synchronous function doesn't give the UI any chance to react on on a change of .isExecuting,isExecuting isn't supported for synchronous commands and will throw an assert if you try to use it. catchAlways : overrides the default set by catchAlwaysDefault. If false, Exceptions thrown by the wrapped function won't be caught but rethrown unless there is a listener on thrownExceptions or results. debugName optional identifier that is included when you register a globalExceptionHandler or a loggingHandler

Implementation

static Command<TParam, TResult> createSync<TParam, TResult>(
    TResult Function(TParam x) func, TResult initialValue,
    {ValueListenable<bool>? restriction,
    bool includeLastResultInCommandResults = false,
    bool? catchAlways,
    String? debugName}) {
  return CommandSync<TParam, TResult>(
      (x) => func(x),
      null,
      initialValue,
      restriction,
      includeLastResultInCommandResults,
      false,
      catchAlways,
      debugName,
      false);
}