Command<TParam, TResult> class abstract

Command capsules a given handler function that can then be run by its run method. The result of this method is then published through its ValueListenable interface Additionally it offers other ValueListenables for it's current execution state, if the command can be run and for all possibly thrown exceptions during command execution.

Command implements the ValueListenable interface so you can register notification handlers directly to the Command which emits the results of the wrapped function. If this function has a void return type registered handler will still be called so that you can listen for the end of the execution.

The results ValueListenable emits CommandResult<TResult> which is often easier in combination with Flutter ValueListenableBuilder because you have all state information at one place.

An Command is a generic class of type Command<TParam, TResult> where TParam is the type of data that is passed when calling run and TResult denotes the return type of the handler function. To signal that a handler doesn't take a parameter or returns no value use the type void

Inheritance
Available extensions

Constructors

Command({required TResult initialValue, required ValueListenable<bool>? restriction, required RunInsteadHandler<TParam>? ifRestrictedRunInstead, @Deprecated('Use ifRestrictedRunInstead instead. ' 'This will be removed in v10.0.0. ' 'See BREAKING_CHANGE_EXECUTE_TO_RUN.md for migration guide.') required ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, required bool includeLastResultInCommandResults, required bool noReturnValue, required bool notifyOnlyWhenValueChanges, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, required String? name, required bool noParamValue})

Properties

asyncNotification bool
If true, the listeners will be notified asynchronously, which can be helpful if you encounter problems that you trigger rebuilds during the build phase.
finalinherited
canExecute ValueListenable<bool>
Deprecated: Use canRun instead. This property will be removed in v10.0.0.
no setter
canRun ValueListenable<bool>
ValueListenable<bool> that changes its value on any change of the current executability state of the command. Meaning if the command can be run or not. This will issue false while the command runs, but also if the command receives a true from the restriction ValueListenable that you can pass when creating the Command. its value is !restriction.value && !isRunning.value
no setter
errors ValueListenable<CommandError<TParam>?>
ValueListenable<CommandError> that reflects the Error State of the command if the wrapped function throws an error, its value is set to the error is wrapped in an CommandError
no setter
errorsDynamic ValueListenable<CommandError?>
Same as errors but with a dynamic error type. This is useful if you have want to merge different error types in one listener.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isCanceled ValueListenable<bool>
Observable cancellation flag.
no setter
isExecuting ValueListenable<bool>
Deprecated: Use isRunning instead. This property will be removed in v10.0.0.
no setter
isExecutingSync ValueListenable<bool>
Deprecated: Use isRunningSync instead. This property will be removed in v10.0.0.
no setter
isRunning ValueListenable<bool>
ValueListenable<bool> that tracks whether the command is currently running.
no setter
isRunningSync ValueListenable<bool>
ValueListenable<bool> that tracks whether the command is currently running.
no setter
listenerCount int
getter/setter pairinherited
mode CustomNotifierMode
finalinherited
name String?
no setter
onError → void Function(Object error, StackTrace stackTrace)?
finalinherited
progress ValueListenable<double>
Observable progress value between 0.0 (0%) and 1.0 (100%).
no setter
results ValueListenable<CommandResult<TParam?, TResult>>
emits CommandResult<TResult> the combined state of the command, which is often easier in combination with Flutter's ValueListenableBuilder because you have all state information at one place.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
statusMessage ValueListenable<String?>
Observable status message providing human-readable operation status.
no setter
thrownExceptions ValueListenable<CommandError<TParam>?>
ValueListenable<CommandError> that reflects the Error State of the command if the wrapped function throws an error, its value is set to the error is wrapped in an CommandError
no setter
value ↔ TResult
The current value of the object. When the value changes, the callbacks registered with addListener will be invoked.
getter/setter pairinherited

Methods

addListener(void listener()) → void
Register a closure to be called when the object changes.
inherited
async({bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

ValueListenable are inherently synchronous. In most cases this is what you want. But if for example your ValueListenable gets updated inside a build method of a widget which would trigger a rebuild because your widgets is listening to the ValueListenable you get an exception that you called setState inside a build method. By using async you push the update of the ValueListenable to the next frame. This way you can update the ValueListenable inside a build method without getting an exception.
call([TParam? param]) → void
This makes Command a callable class, so instead of myCommand.run() you can write myCommand()
cancel() → void
Requests cooperative cancellation of the command execution.
clearErrors() → void
clears the error state of the command. This will trigger any listeners especially useful if you use watch_it to watch the errors property. However the prefered way to handle the errors property is either use registerHandler or listen in initState of a StatefulWidget
combineLatest<TIn2, TOut>(ValueListenable<TIn2> combineWith, CombiningFunction2<T, TIn2, TOut> combiner, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

Imagine having two ValueNotifier in you model and you want to update a certain region of the screen with their values every time one of them get updated. combineLatest combines two ValueListenable in that way that it returns a new ValueNotifier that changes its value of TOut whenever one of the input listenables this or combineWith updates its value. This new value is built by the combiner function that is called on any value change of the input listenables.
combineLatest3<TIn2, TIn3, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, CombiningFunction3<T, TIn2, TIn3, TOut> combiner, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

Similar to what combineLatest does. Only change is you can listen to 3 ValueNotifiers together usage e.g: final subscription = listenable1
combineLatest4<TIn2, TIn3, TIn4, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, ValueListenable<TIn4> combineWith4, CombiningFunction4<T, TIn2, TIn3, TIn4, TOut> combiner, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

Similar to what combineLatest does. Only change is you can listen to 4 ValueNotifiers together usage e.g: final subscription = listenable1
combineLatest5<TIn2, TIn3, TIn4, TIn5, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, ValueListenable<TIn4> combineWith4, ValueListenable<TIn5> combineWith5, CombiningFunction5<T, TIn2, TIn3, TIn4, TIn5, TOut> combiner, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

Similar to what combineLatest does. Only change is you can listen to 5 ValueNotifiers together usage e.g: final subscription = listenable1
combineLatest6<TIn2, TIn3, TIn4, TIn5, TIn6, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, ValueListenable<TIn4> combineWith4, ValueListenable<TIn5> combineWith5, ValueListenable<TIn6> combineWith6, CombiningFunction6<T, TIn2, TIn3, TIn4, TIn5, TIn6, TOut> combiner, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

Similar to what combineLatest does. Only change is you can listen to 6 ValueNotifiers together usage e.g: final subscription = listenable1 .combineLatest6<String, String, String, String, String, String>( listenable2, listenable3, listenable4, listenable5, listenable6, (i, j, k, l, m, s) => "$i:$j:$k:$l:$m:$s") .listen((x, _) { print(x); });
debounce(Duration timeOut, {bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

If you get too much value changes during a short time period and you don't want or can handle them all debounce can help you. If you add a debounce to your listenable processing pipeline the returned ValueListenable will not emit an updated value before at least timpeout time has passed since the last value change. All value changes before will be discarded.
debounce(Duration timeOut) Listenable

Available on Listenable, provided by the FunctionaListener2 extension

dispose() → void
If you don't need a command any longer it is a good practise to dispose it to make sure all registered notification handlers are remove to prevent memory leaks
override
execute([TParam? param]) → void
Deprecated: Use run instead. This method will be removed in v10.0.0.
executeWithFuture([TParam? param]) Future<TResult>
Deprecated: Use runAsync instead. This method will be removed in v10.0.0.
listen(void handler(T, ListenableSubscription)) ListenableSubscription

Available on ValueListenable<T>, provided by the FunctionaListener extension

let you work with a ValueListenable as it should be by installing a handler function that is called on any value change of this and gets the new value passed as an argument. It returns a subscription object that lets you stop the handler from being called by calling cancel() on the subscription. The handler get the subscription object passed on every call so that it is possible to uninstall the handler from the handler itself.
listen(void handler(ListenableSubscription)) ListenableSubscription

Available on Listenable, provided by the FunctionaListener2 extension

let you work with a Listenable as it should be by installing a handler function that is called on any value change of this and gets the new value passed as an argument. It returns a subscription object that lets you stop the handler from being called by calling cancel() on the subscription. The handler get the subscription object passed on every call so that it is possible to uninstall the handler from the handler itself.
map<TResult>(TResult convert(T), {bool lazy = false}) ValueListenable<TResult>

Available on ValueListenable<T>, provided by the FunctionaListener extension

converts a ValueListenable to another type T by returning a new connected ValueListenable<T> on each value change of this the conversion function convert is called to do the type conversion
mergeWith(List<ValueListenable<T>> mergeWith, {bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

Merges value changes of this together with value changes of a List of ValueListenables so that when ever any of them changes the result of mergeWith will change too.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners([void onError(Object error, StackTrace stackTrace)?]) → void
Call all the registered listeners.
inherited
pipeToCommand<TTargetParam, TTargetResult>(Command<TTargetParam, TTargetResult> target, {TTargetParam transform(T value)?}) ListenableSubscription

Available on ValueListenable<T>, provided by the ValueListenablePipe extension

Triggers target command whenever this ValueListenable's value changes.
removeListener(void listener()) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
resetProgress({double? progress, String? statusMessage}) → void
Manually resets all progress state to initial values.
run([TParam? param]) → void
Runs the wrapped function with optional param.
runAsync([TParam? param]) Future<TResult>
Runs an async Command and returns a Future that completes as soon as the Command completes. This is especially useful if you use a RefreshIndicator
select<TResult>(TResult selector(T), {bool lazy = false}) ValueListenable<TResult>

Available on ValueListenable<T>, provided by the FunctionaListener extension

select allows you to set a filter on a ValueListenable like where, and the returned ValueListenable only emit a new value when the returned value of selector function change. With this you can react on a specific value change of a property of the ValueListenable.
toString() String
A string representation of this object.
inherited
toWidget({required Widget onResult(TResult lastResult, TParam? param), Widget whileRunning(TResult lastResult, TParam? param)?, Widget whileExecuting(TResult lastResult, TParam? param)?, Widget onError(Object? error, TParam? param)?}) Widget
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.
where(bool selector(T), {T? fallbackValue, bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

where allows you to set a filter on a ValueListenable so that an installed handler function is only called if the passed selector function returns true. Because the selector function is called on every new value you can change the filter during runtime.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

assertionsAlwaysThrow bool
AssertionErrors are almost never wanted in production, so by default they will dirextly be rethrown, so that they are found early in development In case you want them to be handled like any other error, meaning an ErrorFilter will decide what should happen, set this to false.
getter/setter pair
debugErrorsThrowAlways bool
getter/setter pair
detailedStackTraces bool
Will capture detailed stacktraces for any Command execution. If this has negative impact on performance you can set this to false. This is a global setting for all Commands in the app.
getter/setter pair
errorFilterDefault ErrorFilter
if no individual ErrorFilter is set when creating a Command this filter is used in case of an error
getter/setter pair
globalErrors Stream<CommandError>
Stream of all command errors across the entire application. Emits whenever any command encounters an error that would trigger the globalExceptionHandler (based on ErrorFilter routing).
no setter
globalExceptionHandler ↔ void Function(CommandError error, StackTrace stackTrace)?
optional hander that will get called on any exception that happens inside any Command of the app. Ideal for logging. the name of the Command that was responsible for the error is inside the error object.
getter/setter pair
loggingHandler ↔ void Function(String? commandName, CommandResult result)?
optional handler that will get called on all Command executions if the Command has a set a name. commandName the name of the Command
getter/setter pair
reportAllExceptions bool
overrides any ErrorFilter that is set for a Command and will call the global exception handler for any error that occurs in any Command of the app. Together with the detailledStackTraces this gives detailed information what's going on in the app
getter/setter pair
reportErrorHandlerExceptionsToGlobalHandler bool
if a local error handler is present and that handler throws an exception this flag will decide if the global exception handler will be called with the error of the error handler. In that casse the original error is stored in the originalError property of the CommandError. If set to false such errors will only by the Flutter error logger
getter/setter pair
useChainCapture bool
experimental if enabled you will get a detailed stacktrace of the origin of the exception inside the wrapped function.
getter/setter pair

Static Methods

createAsync<TParam, TResult>(Future<TResult> func(TParam x), {required TResult initialValue, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, TResult>
Creates a Command for an asynchronous 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. true means that the Command cannot be executed. If omitted the command can be executed always except it's already executing ifRestrictedRunInstead 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. 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 or while the command is still running. 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
createAsyncNoParam<TResult>(Future<TResult> func(), {required TResult initialValue, ValueListenable<bool>? restriction, void ifRestrictedRunInstead()?, void ifRestrictedExecuteInstead()?, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, TResult>
Creates a Command for an asynchronous handler function with no 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. true means that the Command cannot be executed. If omitted the command can be executed always except it's already executing ifRestrictedRunInstead 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. 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 or while the command is still running. 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
createAsyncNoParamNoResult(Future<void> action(), {ValueListenable<bool>? restriction, void ifRestrictedRunInstead()?, void ifRestrictedExecuteInstead()?, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, void>
Creates a Command for an asynchronous handler function with no parameter and no return type action : handler function 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. 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 ifRestrictedRunInstead 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. 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
createAsyncNoParamNoResultWithProgress(Future<void> action(ProgressHandle handle), {ValueListenable<bool>? restriction, VoidCallback? ifRestrictedRunInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, String? debugName}) Command<void, void>
Creates an async Command with ProgressHandle for no-parameter, void-return functions.
createAsyncNoParamWithProgress<TResult>(Future<TResult> func(ProgressHandle handle), {required TResult initialValue, ValueListenable<bool>? restriction, VoidCallback? ifRestrictedRunInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, TResult>
Creates an async Command with ProgressHandle for no-parameter functions.
createAsyncNoResult<TParam>(Future<void> action(TParam x), {ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, void>
Creates a Command for an asynchronous handler function with one parameter and no return type action : handler function 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. 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 ifRestrictedRunInstead 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. 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
createAsyncNoResultWithProgress<TParam>(Future<void> action(TParam x, ProgressHandle handle), {ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, String? debugName}) Command<TParam, void>
Creates an async Command with ProgressHandle for void-return functions.
createAsyncWithProgress<TParam, TResult>(Future<TResult> func(TParam x, ProgressHandle handle), {required TResult initialValue, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, TResult>
Creates an async Command with ProgressHandle for progress tracking, status messages, and cooperative cancellation.
createSync<TParam, TResult>(TResult func(TParam x), {required TResult initialValue, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, TResult>
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. true means that the Command cannot be executed. If omitted the command can be executed always except it's already executing ifRestrictedRunInstead 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. 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. errorFilter : overrides the default set by errorFilterDefault. If false, Exceptions thrown by the wrapped function won't be caught but rethrown 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
createSyncNoParam<TResult>(TResult func(), {required TResult initialValue, ValueListenable<bool>? restriction, void ifRestrictedRunInstead()?, void ifRestrictedExecuteInstead()?, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, TResult>
Creates a Command for a synchronous handler function with no 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. true means that the Command cannot be executed. If omitted the command can be executed always except it's already executing ifRestrictedRunInstead 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. 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 any 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. 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
createSyncNoParamNoResult(void action(), {ValueListenable<bool>? restriction, void ifRestrictedRunInstead()?, void ifRestrictedExecuteInstead()?, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, void>
////////////////////// Factory functions from here on //////////////////////
createSyncNoResult<TParam>(void action(TParam x), {ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, void>
Creates a Command for a synchronous handler function with one 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 ifRestrictedRunInstead 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 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. 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
createUndoable<TParam, TResult, TUndoState>(Future<TResult> func(TParam, UndoStack<TUndoState>), {required TResult initialValue, required UndoFn<TUndoState, TResult> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, TResult>
Creates a Command for an asynchronous handler function with parameter that returns a value func : handler function 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. undo : function that undoes the action. initialValue sets the .value of the Command. undoOnExecutionFailure : if true the undo function will be executed automatically if the action fails. 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 ifRestrictedRunInstead 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. 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
createUndoableNoParam<TResult, TUndoState>(Future<TResult> func(UndoStack<TUndoState>), {required TResult initialValue, required UndoFn<TUndoState, TResult> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, void ifRestrictedRunInstead()?, void ifRestrictedExecuteInstead()?, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, TResult>
Creates a undoable Command for an asynchronous handler function with no parameter that returns a value func : handler function 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. undo : function that undoes the action. initialValue sets the .value of the Command. undoOnExecutionFailure : if true the undo function will be executed automatically if the action fails. 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 ifRestrictedRunInstead 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. 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
createUndoableNoParamNoResult<TUndoState>(Future<void> action(UndoStack<TUndoState>), {required UndoFn<TUndoState, void> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, void ifRestrictedRunInstead()?, void ifRestrictedExecuteInstead()?, ErrorFilter? errorFilter = const ErrorHandlerLocal(), ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, void>
Creates an undoable Command for an asynchronous handler function with no parameter and no return type action : handler function 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. undo : function that undoes the action. undoOnExecutionFailure : if true the undo function will be executed automatically if the action fails. 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 ifRestrictedRunInstead 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. 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
createUndoableNoParamNoResultWithProgress<TUndoState>(Future<void> action(ProgressHandle, UndoStack<TUndoState>), {required UndoFn<TUndoState, void> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, VoidCallback? ifRestrictedRunInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, String? debugName}) Command<void, void>
Creates an undoable Command with ProgressHandle for no-parameter, void-return functions.
createUndoableNoParamWithProgress<TResult, TUndoState>(Future<TResult> func(ProgressHandle, UndoStack<TUndoState>), {required TResult initialValue, required UndoFn<TUndoState, TResult> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, VoidCallback? ifRestrictedRunInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<void, TResult>
Creates an undoable Command with ProgressHandle for no-parameter functions.
createUndoableNoResult<TParam, TUndoState>(Future<void> action(TParam, UndoStack<TUndoState>), {required UndoFn<TUndoState, void> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, void>
Creates an undoable Command for an asynchronous handler function with one parameter and no return type action : handler function 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. undo : function that undoes the action. undoOnExecutionFailure : if true the undo function will be executed automatically if the action fails. 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 ifRestrictedRunInstead 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. 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
createUndoableNoResultWithProgress<TParam, TUndoState>(Future<void> action(TParam, ProgressHandle, UndoStack<TUndoState>), {required UndoFn<TUndoState, void> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, String? debugName}) Command<TParam, void>
Creates an undoable Command with ProgressHandle for void-return functions.
createUndoableWithProgress<TParam, TResult, TUndoState>(Future<TResult> func(TParam, ProgressHandle, UndoStack<TUndoState>), {required TResult initialValue, required UndoFn<TUndoState, TResult> undo, bool undoOnExecutionFailure = true, ValueListenable<bool>? restriction, RunInsteadHandler<TParam>? ifRestrictedRunInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, ErrorFilterFn? errorFilterFn, bool notifyOnlyWhenValueChanges = false, String? debugName}) Command<TParam, TResult>
Creates an undoable Command with ProgressHandle for async functions.