/flutter_async_table

A PaginatedDataTable alternative with convenience methods for fetching async data.

Primary LanguageDartMIT LicenseMIT

Flutter Async Table

Pub Version GitHub last commit on main Build GitHub Workflow Status Publish GitHub Workflow Status

A convenience package over PaginatedDataTable optimized for fetching items asynchronously.

Features

  • AsyncTableWidget<T> that wraps a PaginatedDataTable
  • AsyncTableSource<T> that extends a DataTableSource

Getting started

  • Add the package as a dependency in pubspec.yaml
dart pub add async_table

Usage

//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,
        );
    }
);