A convenience package over PaginatedDataTable
optimized for fetching items asynchronously.
AsyncTableWidget<T>
that wraps aPaginatedDataTable
AsyncTableSource<T>
that extends aDataTableSource
- Add the package as a dependency in
pubspec.yaml
dart pub add async_table
//An optional wrapper to handle rowsPerPage
RowsPerPageWrapper(
initialRowsPerPage: initialrowsPerPage,
builder: (context, rowsPerPage, setRowsPerPage) {
return AsyncTableWidget<T>(
requestItems: (offset, rowsPerPage) async {
//send a request to the server here
},
//pass rowsPerPage, availableRowsPerPage, onRowsPerPageChanged
rowsPerPage: rowsPerPage,
onRowsPerPageChanged: setRowsPerPage,
//define the columns, and how each column builds the cell
columns: [
AsyncTableColumnDef(
cellBuilder: (context, item) => DataCell(Text(item.id)),
column: const DataColumn(label: Text('Id')),
),
AsyncTableColumnDef(
cellBuilder: (context, item) => DataCell(Text(item.title)),
column: const DataColumn(label: Text('Title')),
),
],
//store the AsyncTableSource<T> after its creation.
initState: (value) => dataSrc = value,
);
}
);