$for<T> function

ForBLoCWidget<T> $for<T>(
  1. LiveData<List<T>> lv, {
  2. Key? key,
  3. Widget buildList(
    1. BuildContext context,
    2. List<ItemViewHolder<T>> list
    )?,
  4. Widget buildItem(
    1. BuildContext context,
    2. T value,
    3. int index
    )?,
  5. Widget buildEmpty(
    1. BuildContext context,
    2. List<T> list
    )?,
})

Implementation

ForBLoCWidget<T> $for<T>(
  LiveData<List<T>> lv, {
  Key? key,
  Widget Function(BuildContext context, List<ItemViewHolder<T>> list)? buildList,
  Widget Function(BuildContext context, T value, int index)? buildItem,
  Widget Function(BuildContext context, List<T> list)? buildEmpty,
}) {
  buildList ??= (
    BuildContext _context,
    List<ItemViewHolder<T>> items,
  ) {
    return ListView.builder(
      itemCount: items.length,
      itemBuilder: (context, i) => items[i].widget,
    );
  };

  buildItem ??= (BuildContext _context, T value, int _index) {
    return Text('$value');
  };

  return ForBLoCWidget<T>(
    liveData: lv,
    listBuilder: buildList,
    itemBuilder: buildItem,
    emptyBuilder: buildEmpty ?? (_, list) => EmptyWidget(key: key),
  );
}