ExtendedStreamBuilder<T> constructor

ExtendedStreamBuilder<T>({
  1. Key? key,
  2. dynamic initialData,
  3. Stream? stream,
  4. ValueTwoCallbackT<Widget, BuildContext, T>? onNone,
  5. ValueTwoCallbackT<Widget, BuildContext, T>? onWaiting,
  6. ValueTwoCallbackT<Widget, BuildContext, T>? onActive,
  7. ValueTwoCallbackT<Widget, BuildContext, T>? onDone,
  8. ValueTwoCallbackT<Widget, BuildContext, Object?>? onError,
})

Implementation

ExtendedStreamBuilder({
  super.key,
  super.initialData,
  super.stream,

  /// [ConnectionState.none] 显示的内容
  ValueTwoCallbackT<Widget, BuildContext, T>? onNone,

  /// [ConnectionState.waiting] 显示的内容
  ValueTwoCallbackT<Widget, BuildContext, T>? onWaiting,

  /// [ConnectionState.active] 显示的内容
  ValueTwoCallbackT<Widget, BuildContext, T>? onActive,

  /// [ConnectionState.done] 显示的内容
  ValueTwoCallbackT<Widget, BuildContext, T>? onDone,

  /// [error] 显示的内容
  ValueTwoCallbackT<Widget, BuildContext, Object?>? onError,
}) : super(builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
        if (snapshot.hasError) {
          return onError?.call(context, snapshot.error) ?? const SizedBox();
        }
        switch (snapshot.connectionState) {
          case ConnectionState.none:
            return onNone?.call(context, snapshot.data) ?? const SizedBox();
          case ConnectionState.waiting:
            return onWaiting?.call(context, snapshot.data) ??
                const SizedBox();
          case ConnectionState.active:
            return onActive?.call(context, snapshot.data) ?? const SizedBox();
          case ConnectionState.done:
            return onDone?.call(context, snapshot.data) ?? const SizedBox();
        }
      });