Skip to content

Instantly share code, notes, and snippets.

@dhruvilp
Created December 15, 2020 23:55
Show Gist options
  • Select an option

  • Save dhruvilp/9dfd4c0abef04be7d467856e37a0407d to your computer and use it in GitHub Desktop.

Select an option

Save dhruvilp/9dfd4c0abef04be7d467856e37a0407d to your computer and use it in GitHub Desktop.
Flutter PaginatedDataTable
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.blueGrey.shade100,
body: Center(
child: MyWidget(),
),
),
);
}
}
class DTS extends DataTableSource {
@override
DataRow getRow(int index) {
return DataRow.byIndex(
index: index,
cells: [
DataCell(Text('#cel1$index')),
DataCell(Text('#cel2$index')),
DataCell(Text('#cel3$index')),
DataCell(Text('#cel4$index')),
DataCell(Text('#cel5$index')),
DataCell(Text('#cel6$index')),
],
);
}
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => 100;
@override
int get selectedRowCount => 0;
}
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
List<bool> selected = List<bool>.generate(100, (index) => false);
var dts = DTS();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(15.0),
child: Container(
width: 600.0,
child: SingleChildScrollView(
child: PaginatedDataTable(
header: Text('Paginated Data Table'),
sortAscending: true,
showCheckboxColumn: true,
columns: [
DataColumn(label: Text('Col 1')),
DataColumn(label: Text('Col 2')),
DataColumn(label: Text('Col 3')),
DataColumn(label: Text('Col 4')),
DataColumn(label: Text('Col 5')),
DataColumn(label: Text('Col 6')),
],
source: dts,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment