build method

  1. @override
Widget build(
  1. BuildContext context
)

Implementation

@override
Widget build(BuildContext context) {
  // Check if widget is visible before wasting resources on building it
  if (!widget.model.visible) return const Offstage();

  // build style
  if (grid == null) {

    // build the columns
    _buildColumns();

    var config = _buildConfig();

    // Busy / Loading Indicator
    if (widget.model.showBusy) {
      busy ??= BusyModel(widget.model,
          visible: widget.model.busy,
          observable: widget.model.busyObservable)
          .getView();
    }

    // paged grid
    paged = widget.model.pageSize > 0;

    // Initial empty row set
    List<PlutoRow> rows = [];

    // build the grid
    // UniqueKey() is necessary otherwise the grid will not recreate itself on header changes
    grid = PlutoGrid(
        key: UniqueKey(),
        configuration: config,
        columnGroups: groups,
        columns: columns.toList(),
        rows: rows,
        mode: PlutoGridMode.normal,
        onLoaded: onLoadedHandler,
        onSorted: onSortedHandler,
        onChanged: onChangedHandler,
        onRowDoubleTap: onDeselectHandler,
        onRowsMoved: onRowsMoved,
        //onSelected: onSelectedHandler,
        noRowsWidget: widget.model.noData?.getView(),
        createFooter: paged ? _pageLoader : _lazyLoader);
  } else {
    // fit last column to fill table
    var fit = widget.model.header?.fit?.trim().toLowerCase();
    if (fit == "fill") {
      WidgetsBinding.instance
          .addPostFrameCallback((_) => _fitLastColumnWidth());
    }
  }

  // apply constraints
  var view = applyConstraints(grid!, widget.model.constraints);

  // add margins around the entire widget
  view = addMargins(view);

  // apply visual transforms
  view = applyTransforms(view);

  // display busy widget over table
  if (widget.model.showBusy) {
    view = Stack(children: [view, Center(child: busy)]);
  }

  return view;
}