Created
December 23, 2024 14:18
-
-
Save iapicca/8e489f2af93b644b4ca0aede6a827b13 to your computer and use it in GitHub Desktop.
issue_160776
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(context) => MaterialApp(home: DataTableDemo()); | |
} | |
class DataTableDemo extends StatelessWidget { | |
const DataTableDemo({super.key}); | |
@override | |
Widget build(context) => Scaffold( | |
body: ListView( | |
padding: const EdgeInsets.all(16), | |
children: [ | |
PaginatedDataTable( | |
header: Text('Header Text'), | |
rowsPerPage: 4, | |
columns: [ | |
DataColumn(label: Text('Header A')), | |
DataColumn(label: Text('Header B')), | |
DataColumn(label: Text('Header C')), | |
DataColumn(label: Text('Header D')), | |
], | |
source: DataSource(), | |
), | |
], | |
), | |
); | |
} | |
class Row { | |
Row(this.valueA, this.valueB, this.valueC, this.valueD); | |
final String valueA, valueB, valueC; | |
final int valueD; | |
var selected = false; | |
List<DataCell> get cells => [ | |
DataCell(Text(valueA)), | |
DataCell(Text(valueB)), | |
DataCell(Text(valueC)), | |
DataCell(Text(valueD.toString())), | |
]; | |
} | |
class DataSource extends DataTableSource { | |
DataSource(); | |
final _rows = [ | |
Row('Cell A1', 'CellB1', 'CellC1', 1), | |
Row('Cell A2', 'CellB2', 'CellC2', 2), | |
Row('Cell A3', 'CellB3', 'CellC3', 3), | |
Row('Cell A4', 'CellB4', 'CellC4', 4), | |
]; | |
@override | |
DataRow? getRow(int index) { | |
if (index >= _rows.length) return null; | |
final row = _rows[index]; | |
return DataRow.byIndex( | |
index: index, | |
selected: row.selected, | |
onSelectChanged: (value) {}, | |
cells: row.cells, | |
); | |
} | |
@override | |
int get rowCount => _rows.length; | |
@override | |
final isRowCountApproximate = false; | |
@override | |
int get selectedRowCount => 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment