AsyncNotifier<T> constructor

AsyncNotifier<T>({
  1. T? data,
  2. Object? error,
  3. StackTrace stackTrace = StackTrace.empty,
  4. ConnectionState state = ConnectionState.none,
  5. void onData(
    1. T data
    )?,
  6. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
  7. void onDone()?,
  8. 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.

Example:

final notifier = AsyncNotifier<List<Todo>>();

Implementation

AsyncNotifier({
  T? data,
  Object? error,
  StackTrace stackTrace = StackTrace.empty,
  ConnectionState state = ConnectionState.none,
  void Function(T data)? onData,
  void Function(Object error, StackTrace stackTrace)? onError,
  void Function()? onDone,
  this.cancelOnError,
})  : _callbacks = (onData: onData, onError: onError, onDone: onDone),
      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),
      ) {
  observer?.onCreate(this);
}