Promise<T>.fromSnapshot constructor

Promise<T>.fromSnapshot(
  1. AsyncSnapshot<T> snapshot
)

Implementation

factory Promise.fromSnapshot(AsyncSnapshot<T> snapshot) {
  switch (snapshot.connectionState) {
    case ConnectionState.none:
    case ConnectionState.waiting:
      return const Promise.loading();
    case ConnectionState.active:
      return snapshot.hasError
          ? Promise.error(snapshot.error)
          : Promise.data(snapshot.data as T, isDone: false);
    case ConnectionState.done:
      return snapshot.hasError
          ? Promise.error(snapshot.error)
          : Promise.data(snapshot.data as T);
  }
}