cellBuilder method
Widget
cellBuilder(
- PlutoColumnRendererContext context,
- bool hasEnterableFields
)
Implementation
Widget cellBuilder(
PlutoColumnRendererContext context, bool hasEnterableFields) {
// get row and column indexes
var rowIdx = rows.indexOf(context.row);
var colIdx =
map.containsKey(context.column) ? map[context.column]!.index : -1;
// not found
if (rowIdx.isNegative || colIdx.isNegative) return const Text("");
// get cell model
TableRowCellModel? model = widget.model.getRowCellModel(rowIdx, colIdx);
if (model == null) return const Text("");
// return the view
if (!views.containsKey(model)) {
// build the view
Widget view = RepaintBoundary(child: BoxView(model));
// cache the view
views[model] = view;
}
// we must wrap the cell in a listener to select the row on tap
// this isn't necessarily required if the cell doesn't have a gesture detector, onclick, etc
// without this, the onTap (select) is consumed by the child view
var cell = Listener(
child: views[model],
onPointerDown: (_) => onTap(context.cell, context.rowIdx));
// we override the key listener in order to enable input on
// enterable fields
return hasEnterableFields
? FocusScope(
child: cell,
onKeyEvent: (FocusNode focusNode, KeyEvent event) =>
KeyEventResult.skipRemainingHandlers)
: cell;
}