flutter_command library

Classes

Command<TParam, TResult>
Command capsules a given handler function that can then be executed by its execute 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 executed and for all possibly thrown exceptions during command execution.
CommandAsync<TParam, TResult>
CommandBuilder<TParam, TResult>
CommandError<TParam>
CommandError wraps an occurring error together with the argument that was passed when the command was called. This sort of objects are emitted on the .errors ValueListenable of the Command
CommandResult<TParam, TResult>
Combined execution state of a Command represented using four of its fields. A CommandResult will be issued for any state change of any of its fields During normal command execution you will get this items by listening at the command's .results ValueListenable.
CommandSync<TParam, TResult>
CustomValueNotifier<T>
Sometimes you want a ValueNotifier where you can control when its listeners are notified. With the CustomValueNotifier you can do this: If you pass CustomNotifierMode.always for the mode parameter, notifierListeners will be called everytime you assign a value to the value property independent of if the value is different from the previous one. If you pass CustomNotifierMode.manual for the mode parameter, notifierListeners will not be called when you assign a value to the value property. You have to call it manually to notify the Listeners. Aditionally it has a listenerCount property that tells you how many listeners are currently listening to the notifier.
ErrorFilter
Instead of the current parameter catchAlways commands can get an optional parameter errorFilter of type ErrorFilter which can be used to customize the error handling. Additionally there will be a Global error Filter that is used if no local error filter is present.
ErrorFilterExcemption<T>
ErrorHandlerGlobalIfNoLocal
ErrorHandlerLocal
ErrorHandlerLocalAndGlobal
ListenableSubscription
Object that is returned by listen that allows you to stop the calling of the handler that you passed to it.
MockCommand<TParam, TResult>
MockCommand allows you to easily mock an Command for your Unit and UI tests Mocking a command with mockito https://pub.dartlang.org/packages/mockito has its limitations.
PredicatesErrorFilter
Takes a list of predicate functions and returns the first non null ErrorReaction or ErrorReaction.defaultHandler if no predicate matches. The predicates are called in the order of the list. which means if you want to match against a type hierarchy you have to put the more specific type first. You can define your own predicates or use the errorFilter function like this
TableErrorFilter
This filter allows to pass a table of error types and the corresponding ErrorReactions. Attention, the table can only compare the runtime type of the error on equality, not the type hierarchy. Normally you couldn't match against the Excpeption type, because the runtime type of an exception is always _Exception which is a private type. As Exception is such a basic error type this funcion has a workaround for this case. I recommend to use the PredicatesErrorFilter instead unless you have a very specific use case that requires to compare for type equality.
UndoableCommand<TParam, TResult, TUndoState>
UndoStack<E>

Extensions

FunctionaListener on ValueListenable<T>
extension functions on ValueListenable that allows you to work with them almost as if it was a synchronous stream. Each extension function returns a new ValueNotifier that updates its value when the value of this changes You can chain these functions to build complex processing pipelines from a simple ValueListenable In the examples we use listen to react on value changes. Instead of applying listen you could also pass the end of the function chain to a ValueListenableBuilder
ToWidgeCommandResult on CommandResult<TParam, TResult>

Functions

errorFilter<TError>(Object error, ErrorReaction reaction) ErrorReaction?

Typedefs

ErrorFilterPredicate = ErrorReaction? Function(Object error, StackTrace stackTrace)
ExecuteInsteadHandler<TParam> = void Function(TParam?)
UndoFn<TUndoState, TResult> = FutureOr<TResult> Function(UndoStack<TUndoState> undoStack, Object? reason)
Type signature of a function that is called when the last command call should be undone.

Exceptions / Errors

UndoException
In case that an undo of a command fails, this exception wraps the error to distinguish it from other exceptions.