MockCommand<TParam, TResult> class

MockCommand allows you to easily mock an Command for your Unit and UI tests Mocking a command with mockito https://pub-web.flutter-io.cn/packages/mockito has its limitations.

Inheritance
Available Extensions

Constructors

MockCommand({required TResult? initialValue, bool noParamValue = false, bool noReturnValue = false, ValueListenable<bool>? restriction, ExecuteInsteadHandler<TParam>? ifRestrictedExecuteInstead, bool includeLastResultInCommandResults = false, ErrorFilter? errorFilter, bool notifyOnlyWhenValueChanges = false, String? debugName})
constructor that can take an optional ValueListenable to control if the command can be execute if the wrapped function has void as return type noResult has to be true

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>
ValueListenable<bool> that changes its value on any change of the current executability state of the command. Meaning if the command can be executed or not. This will issue false while the command executes, 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 && !isExecuting.value
no setterinherited
debugName String?
no setterinherited
errors ValueListenable<CommandError?>
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 setterinherited
executionCount int
Number of times execute or the command directly was called
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isExecuting ValueListenable<bool>
ValueListenable that changes its value on any change of the execution state change of the command
no setterinherited
lastPassedValueToExecute ↔ TParam?
the last value that was passed when execute or the command directly was called
getter/setter pair
listenerCount int
getter/setter pairinherited
mode CustomNotifierMode
finalinherited
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 setterinherited
returnValuesForNextExecute List<CommandResult<TParam, TResult>>?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
thrownExceptions ValueListenable<CommandError?>
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 setterinherited
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
call([TParam? param]) → void
This makes Command a callable class, so instead of myCommand.execute() you can write myCommand()
inherited
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 thd errors property is either user registerHandler or listen in initState of a StatefulWidget
inherited
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
inherited
endExecutionNoData() → void
endExecutionNoData will issue a CommandResult with data: null error: null isExecuting : false
endExecutionWithData(TResult data) → void
endExecutionWithData will issue a CommandResult with data: data error: null isExecuting : false
endExecutionWithError(String message) → void
endExecutionWithData will issue a CommandResult with data: null error: Exception(message) isExecuting : false
execute([TParam? param]) → void
Can either be called directly or by calling the object itself because Commands are callable classes Will increase executionCount and assign lastPassedValueToExecute the value of param If you have queued a result with queueResultsForNextExecuteCall it will be copies tho the output stream. isExecuting, canExecute and results will work as with a real command.
override
executeWithFuture([TParam? param]) Future<TResult?>
Executes an async Command and returns a Future that completes as soon as the Command completes. This is especially useful if you use a RefreshIndicator
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
queueResultsForNextExecuteCall(List<CommandResult<TParam, TResult>> values) → void
to be able to simulate any output of the command when it is called you can here queue the output data for the next execution call
removeListener(void listener()) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
startExecution([TParam? param]) → void
For a more fine grained control to simulate the different states of an Command there are these functions startExecution will issue a CommandResult with data: null error: null isExecuting : true
toString() String
A string representation of this object.
inherited
toWidget({required Widget onResult(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.
inherited

Operators

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