getReactiveBuilder<T> function

AsyncWidgetBuilder<T> getReactiveBuilder<T>({
  1. required DataWidgetBuilder<T?> onData,
  2. required Widget onFallback,
  3. required Widget? onWaiting,
})

Implementation

AsyncWidgetBuilder<T> getReactiveBuilder<T>({
  required DataWidgetBuilder<T?> onData,
  required Widget onFallback,
  required Widget? onWaiting,
}) {
  return (BuildContext context, AsyncSnapshot<T> snapshot) {
    if (snapshot.hasData)
      return onData(snapshot.data);
    else
      switch (snapshot.connectionState) {
        case ConnectionState.active:
          return onFallback;
        default:
          if (snapshot.hasError)
            return onFallback;
          else
            return onWaiting ?? onFallback;
      }
  };
}