itemBuilder method

Widget? itemBuilder(
  1. BuildContext context,
  2. int rowIndex
)

Implementation

Widget? itemBuilder(BuildContext context, int rowIndex) {
  int startIndex = (rowIndex * count);
  int endIndex = (startIndex + count);

  // If all rows are built return null
  if (startIndex >= widget.model.items.length) return null;

  List<Widget> children = [];
  for (int i = startIndex; i < endIndex; i++) {
    if (i < widget.model.items.length) {
      // create the view
      var model = widget.model.items[i]!;
      Widget view = GridItemView(model);

      // droppable?
      if (model.droppable) {
        view = DroppableView(model, view);
      }

      // draggable?
      if (model.draggable) {
        view = DraggableView(model, view);
      }

      // wrap for selectable
      view = MouseRegion(cursor: SystemMouseCursors.click, child: view);
      view = GestureDetector(
          onTap: () => model.onTap(),
          behavior: HitTestBehavior.translucent,
          child: view);

      // add view to child list
      children.add(Expanded(
          child: SizedBox(
              width: prototypeWidth, height: prototypeHeight, child: view)));
    } else {
      // add empty placeholder
      children.add(Expanded(child: Container()));
    }
  }

  if (direction == Axis.vertical) {
    return Row(mainAxisSize: MainAxisSize.min, children: children);
  } else {
    return Column(mainAxisSize: MainAxisSize.min, children: children);
  }
}