$scene<Data, Loading, Error> function

BaseBLoCWidget $scene<Data, Loading, Error>(
  1. LiveScene<Data, Loading, Error> state, {
  2. Key? key,
  3. required Widget child(
    1. BuildContext context,
    2. Data data
    ),
  4. required Widget onEmptyData(
    1. BuildContext context
    ),
  5. required Widget onLoading(
    1. BuildContext context,
    2. Loading loading
    ),
  6. required Widget onError(
    1. BuildContext context,
    2. Error error
    ),
})

Implementation

BaseBLoCWidget $scene<Data, Loading, Error>(
  LiveScene<Data, Loading, Error> state, {
  Key? key,
  required Widget Function(BuildContext context, Data data) child,
  required Widget Function(BuildContext context) onEmptyData,
  required Widget Function(BuildContext context, Loading loading) onLoading,
  required Widget Function(BuildContext context, Error error) onError,
}) {
  // return BaseBLoCWidget(key: key);
  return $guard.isNotNull(
        state.error,
        build: (context, Error? error) {
          return BLoCWidget(
            child: (context, {key}) {
              return onError(context, error!);
            },
          );
        },
      ) |
      $guard(
        state.loading,
        when: (data) => data != null || (data is bool && data),
        build: (context, Loading? loading) {
          return BLoCWidget(
            child: (context, {key}) {
              return onLoading(context, loading!);
            },
          );
        },
      ) |
      $guard(
        state.data,
        when: (data) => data == null || (data is List && data.isEmpty),
        build: (context, Data? data) {
          return BLoCWidget(
            child: (context, {key}) {
              return onEmptyData(context);
            },
          );
        },
      ) |
      $watch(
        state.data,
        build: (context, Data? data) {
          return child(context, data!);
        },
      );
}