fetch method Null safety

Future<T> fetch(
  1. Future<T> callback(
      )
    )

    Returns a cached value from a previous call to fetch, or runs callback to compute a new one.

    If fetch has been called recently enough, returns its previous return value. Otherwise, runs callback and returns its new return value.

    Implementation

    Future<T> fetch(Future<T> Function() callback) async {
      if (_cachedStreamSplitter != null) {
        throw StateError('Previously used to cache via `fetchStream`');
      }
      final result = _cachedValueFuture ??= callback();
      try {
        return await result;
      } finally {
        _startStaleTimer();
      }
    }