SideEffects<T>.onAll constructor

SideEffects<T>.onAll({
  1. required void onWaiting()?,
  2. required void onError(
    1. dynamic err,
    2. VoidCallback refresh
    )?,
  3. required void onData(
    1. T data
    )?,
  4. void initState()?,
  5. void dispose()?,
})

Handle all possible for state status. Null argument will be ignored.

Implementation

factory SideEffects.onAll({
  required void Function()? onWaiting,
  required void Function(dynamic err, VoidCallback refresh)? onError,
  required void Function(T data)? onData,
  void Function()? initState,
  void Function()? dispose,
}) {
  return SideEffects(
    initState: initState,
    dispose: dispose,
    onSetState: (snap) {
      if (snap.isWaiting) {
        onWaiting?.call();
        return;
      }
      if (snap.hasError) {
        onError?.call(snap.snapError!.error, snap.snapError!.refresher);
        return;
      }
      onData?.call(snap.data as T);
    },
  );
}