updateOrNull method

Future<void> updateOrNull(
  1. FutureOr<T> update(
    1. T? old
    ), {
  2. dynamic onError(
    1. Object e,
    2. StackTrace s
    )?,
})

if State init value is null, you can use updateOrNull

Implementation

Future<void> updateOrNull(
  FutureOr<T> Function(T? old) update, {
  Function(Object e, StackTrace s)? onError,
}) async {
  try {
    final data = await update(valueOrNull);
    put(data);
  } catch (e, s) {
    onError?.call(e, s);
    if (onError == null) putError(e, s);
  }
}