createSyncNoParamNoResult static method
- void action(), {
- ValueListenable<
bool> ? restriction, - void ifRestrictedExecuteInstead()?,
- ErrorFilter? errorFilter,
- bool notifyOnlyWhenValueChanges = false,
- String? debugName,
////////////////////// Factory functions from here on //////////////////////
Creates a Command for a synchronous handler function with no parameter and no return type
action
: handler function
restriction
: ValueListenable<bool>
that can be used to enable/disable
the command based on some other state change. true
means that the Command cannot be executed.
If omitted the command can be executed always except it's already executing
ifRestrictedExecuteInstead
if restriction
is set for the command and its value is true
this function will be called instead of the wrapped function.
This is useful if you want to execute a different function when the command
is restricted. For example you could show a dialog to let the user logg in
if the restriction is because the user is not logged in.
If you don't set this function, the command will just do nothing when it's
restricted.
As synchronous function doesn't give any the UI any chance to react on on a change of
.isExecuting
,isExecuting isn't supported for synchronous commands ans will throw an
assert if you try to use it.
Can't be used with an ValueListenableBuilder
because it doesn't have a value, but you can
register a handler to wait for the completion of the wrapped function.
errorFilter
: overrides the default set by errorFilterDefault.
If false
, Exceptions thrown by the wrapped function won't be caught but rethrown
unless there is a listener on errors or results.
notifyOnlyWhenValueChanges
: the default is that the command notifies it's listeners even
if the value hasn't changed. If you set this to true
the command will only notify
it's listeners if the value has changed.
debugName
optional identifier that is included when you register a globalExceptionHandler
or a loggingHandler
Implementation
///
/// Creates a Command for a synchronous handler function with no parameter and no return type
/// [action] : handler function
/// [restriction] : `ValueListenable<bool>` that can be used to enable/disable
/// the command based on some other state change. `true` means that the Command cannot be executed.
/// If omitted the command can be executed always except it's already executing
/// [ifRestrictedExecuteInstead] if [restriction] is set for the command and its value is `true`
/// this function will be called instead of the wrapped function.
/// This is useful if you want to execute a different function when the command
/// is restricted. For example you could show a dialog to let the user logg in
/// if the restriction is because the user is not logged in.
/// If you don't set this function, the command will just do nothing when it's
/// restricted.
/// As synchronous function doesn't give any the UI any chance to react on on a change of
/// `.isExecuting`,isExecuting isn't supported for synchronous commands ans will throw an
/// assert if you try to use it.
/// Can't be used with an `ValueListenableBuilder` because it doesn't have a value, but you can
/// register a handler to wait for the completion of the wrapped function.
/// [errorFilter] : overrides the default set by [errorFilterDefault].
/// If `false`, Exceptions thrown by the wrapped function won't be caught but rethrown
/// unless there is a listener on [errors] or [results].
/// [notifyOnlyWhenValueChanges] : the default is that the command notifies it's listeners even
/// if the value hasn't changed. If you set this to `true` the command will only notify
/// it's listeners if the value has changed.
/// [debugName] optional identifier that is included when you register a [globalExceptionHandler]
/// or a [loggingHandler]
static Command<void, void> createSyncNoParamNoResult(
void Function() action, {
ValueListenable<bool>? restriction,
void Function()? ifRestrictedExecuteInstead,
ErrorFilter? errorFilter,
bool notifyOnlyWhenValueChanges = false,
String? debugName,
}) {
return CommandSync<void, void>(
funcNoParam: action,
initialValue: null,
restriction: restriction,
ifRestrictedExecuteInstead: ifRestrictedExecuteInstead != null
? (_) => ifRestrictedExecuteInstead()
: null,
includeLastResultInCommandResults: false,
noReturnValue: true,
errorFilter: errorFilter,
notifyOnlyWhenValueChanges: notifyOnlyWhenValueChanges,
debugName: debugName,
noParamValue: true,
);
}