DynamicTable constructor

DynamicTable({
  1. Key? key,
  2. bool showActions = false,
  3. Widget? header,
  4. List<Widget>? actions,
  5. required List<DynamicTableDataColumn> columns,
  6. int? sortColumnIndex,
  7. bool sortAscending = true,
  8. ValueSetter<bool?>? onSelectAll,
  9. double dataRowMinHeight = kMinInteractiveDimension,
  10. double dataRowMaxHeight = kMinInteractiveDimension,
  11. double headingRowHeight = 56.0,
  12. double horizontalMargin = 24.0,
  13. double columnSpacing = 56.0,
  14. bool showCheckboxColumn = true,
  15. bool showFirstLastButtons = false,
  16. int? initialFirstRowIndex = 0,
  17. ValueChanged<int>? onPageChanged,
  18. int rowsPerPage = defaultRowsPerPage,
  19. List<int> availableRowsPerPage = const <int>[defaultRowsPerPage, defaultRowsPerPage * 2, defaultRowsPerPage * 5, defaultRowsPerPage * 10],
  20. ValueChanged<int?>? onRowsPerPageChanged,
  21. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  22. Color? arrowHeadColor,
  23. double? checkboxHorizontalMargin,
  24. ScrollController? controller,
  25. bool? primary,
  26. bool onRowEdit(
    1. int index,
    2. List row
    )?,
  27. required List<DynamicTableDataRow> rows,
  28. String actionColumnTitle = "Actions",
  29. bool onRowDelete(
    1. int index,
    2. List row
    )?,
  30. List? onRowSave(
    1. int index,
    2. List oldValue,
    3. List newValue
    )?,
  31. bool showDeleteAction = false,
  32. bool showAddRowButton = false,
})

Creates a widget describing a paginated DataTable on a Card.

The header should give the card's header, typically a Text widget.

The columns argument must be a list of as many DataColumn objects as the table is to have columns, ignoring the leading checkbox column if any. The columns argument must have a length greater than zero and cannot be null.

If the table is sorted, the column that provides the current primary key should be specified by index in sortColumnIndex, 0 meaning the first column in columns, 1 being the next one, and so forth.

The actual sort order can be specified using sortAscending; if the sort order is ascending, this should be true (the default), otherwise it should be false.

The source must not be null. The source should be a long-lived DataTableSource. The same source should be provided each time a particular PaginatedDataTable widget is created; avoid creating a new DataTableSource with each new instance of the PaginatedDataTable widget unless the data table really is to now show entirely different data from a new source.

The rowsPerPage and availableRowsPerPage must not be null (they both have defaults, though, so don't have to be specified).

Themed by DataTableTheme. DataTableThemeData.decoration is ignored. To modify the border or background color of the PaginatedDataTable, use CardTheme, since a Card wraps the inner DataTable.

Implementation

DynamicTable({
  super.key,
  this.showActions = false,
  this.header,
  this.actions,
  required this.columns,
  this.sortColumnIndex,
  this.sortAscending = true,
  this.onSelectAll,
  this.dataRowMinHeight = kMinInteractiveDimension,
  this.dataRowMaxHeight = kMinInteractiveDimension,
  this.headingRowHeight = 56.0,
  this.horizontalMargin = 24.0,
  this.columnSpacing = 56.0,
  this.showCheckboxColumn = true,
  this.showFirstLastButtons = false,
  this.initialFirstRowIndex = 0,
  this.onPageChanged,
  this.rowsPerPage = defaultRowsPerPage,
  this.availableRowsPerPage = const <int>[
    defaultRowsPerPage,
    defaultRowsPerPage * 2,
    defaultRowsPerPage * 5,
    defaultRowsPerPage * 10
  ],
  this.onRowsPerPageChanged,
  this.dragStartBehavior = DragStartBehavior.start,
  this.arrowHeadColor,
  this.checkboxHorizontalMargin,
  this.controller,
  this.primary,
  this.onRowEdit,
  required this.rows,
  this.actionColumnTitle = "Actions",
  this.onRowDelete,
  this.onRowSave,
  this.showDeleteAction = false,
  this.showAddRowButton = false,
})  : assert(() {
        if ((onRowEdit == null && onRowSave != null) ||
            (onRowEdit != null && onRowSave == null)) {
          return false;
        } else {
          return true;
        }
      }(), "onRowEdit and onRowSave must be both null or both non-null"),
      assert(() {
        if (showAddRowButton == true && showActions == false) {
          return false;
        } else {
          return true;
        }
      }(),
          "showActions cannot be false if showAddRowButton is true, because the actions column is required to save the new row");