AsyncNotifier<T> constructor
AsyncNotifier<T> ({
- T? data,
- Object? error,
- StackTrace stackTrace = StackTrace.empty,
- ConnectionState state = ConnectionState.none,
- bool? cancelOnError,
Creates an AsyncNotifier instance with an initial value of type T.
The AsyncNotifier is designed to work with asynchronous operations that
also produce data of type T.
data: The initial AsyncSnapshot.data.error: The initial AsyncSnapshot.error.stackTrace: The initial AsyncSnapshot.stackTrace.state: The initial AsyncSnapshot.connectionState.cancelOnError: Whether the subscription should be canceled when an error occurs.
Example:
final notifier = AsyncNotifier<List<Todo>>();
Implementation
AsyncNotifier({
T? data,
Object? error,
StackTrace stackTrace = StackTrace.empty,
ConnectionState state = ConnectionState.none,
this.cancelOnError,
}) : assert(data == null || error == null),
super(
error != null
? AsyncSnapshot.withError(state, error, stackTrace)
: data is T
? AsyncSnapshot.withData(state, data)
: AsyncSnapshot<T>.nothing().inState(state),
);