add dividerThickness in PaginatedDataTable (#156442)
Transitioned from `DataTable` to `PaginatedDataTable` and noted that the latter is missing the `dividerThickness`, hence this PR adds `dividerThickness` to `PaginatedDataTable`.
This commit is contained in:
@@ -122,6 +122,7 @@ class PaginatedDataTable extends StatefulWidget {
|
||||
this.controller,
|
||||
this.primary,
|
||||
this.headingRowColor,
|
||||
this.dividerThickness,
|
||||
this.showEmptyRows = true,
|
||||
}) : assert(actions == null || (header != null)),
|
||||
assert(columns.isNotEmpty),
|
||||
@@ -132,6 +133,7 @@ class PaginatedDataTable extends StatefulWidget {
|
||||
dataRowMinHeight = dataRowHeight ?? dataRowMinHeight,
|
||||
dataRowMaxHeight = dataRowHeight ?? dataRowMaxHeight,
|
||||
assert(rowsPerPage > 0),
|
||||
assert(dividerThickness == null || dividerThickness >= 0),
|
||||
assert(() {
|
||||
if (onRowsPerPageChanged != null) {
|
||||
assert(availableRowsPerPage.contains(rowsPerPage));
|
||||
@@ -239,6 +241,13 @@ class PaginatedDataTable extends StatefulWidget {
|
||||
/// The index of the first row to display when the widget is first created.
|
||||
final int? initialFirstRowIndex;
|
||||
|
||||
|
||||
/// {@macro flutter.material.dataTable.dividerThickness}
|
||||
///
|
||||
/// If null, [DataTableThemeData.dividerThickness] is used. This value
|
||||
/// defaults to 1.0.
|
||||
final double? dividerThickness;
|
||||
|
||||
/// Invoked when the user switches to another page.
|
||||
///
|
||||
/// The value is the index of the first row on the currently displayed page.
|
||||
@@ -610,6 +619,7 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
|
||||
sortColumnIndex: widget.sortColumnIndex,
|
||||
sortAscending: widget.sortAscending,
|
||||
onSelectAll: widget.onSelectAll,
|
||||
dividerThickness: widget.dividerThickness,
|
||||
// Make sure no decoration is set on the DataTable
|
||||
// from the theme, as its already wrapped in a Card.
|
||||
decoration: const BoxDecoration(),
|
||||
|
||||
@@ -1413,4 +1413,65 @@ void main() {
|
||||
final BoxDecoration tableRowBoxDecoration = tableRow.decoration! as BoxDecoration;
|
||||
expect(tableRowBoxDecoration.color, headingRowColor.resolve(<MaterialState>{}));
|
||||
});
|
||||
|
||||
testWidgets('PaginatedDataTable respects custom dividerThickness', (WidgetTester tester) async {
|
||||
const double dividerThickness = 2.0;
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
body: PaginatedDataTable(
|
||||
primary: true,
|
||||
header: const Text('Test table'),
|
||||
source: source,
|
||||
rowsPerPage: 2,
|
||||
dividerThickness: dividerThickness,
|
||||
columns: const <DataColumn>[
|
||||
DataColumn(label: Text('Name')),
|
||||
DataColumn(label: Text('Calories'), numeric: true),
|
||||
DataColumn(label: Text('Generation')),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
expect(find.byType(Table), findsOneWidget);
|
||||
final Table table = tester.widget(find.byType(Table));
|
||||
final TableRow tableRow = table.children[0];
|
||||
final BoxDecoration? tableRowBoxDecoration = tableRow.decoration as BoxDecoration?;
|
||||
expect(tableRowBoxDecoration, isNotNull);
|
||||
expect(tableRowBoxDecoration?.border, isA<Border>());
|
||||
|
||||
final Border? border = tableRowBoxDecoration?.border as Border?;
|
||||
expect(border?.bottom.width, dividerThickness);
|
||||
});
|
||||
|
||||
testWidgets('PaginatedDataTable respects default dividerThickness', (WidgetTester tester) async {
|
||||
const double defaultDividerThickness = 1.0;
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
body: PaginatedDataTable(
|
||||
primary: true,
|
||||
header: const Text('Test table'),
|
||||
source: source,
|
||||
rowsPerPage: 2,
|
||||
columns: const <DataColumn>[
|
||||
DataColumn(label: Text('Name')),
|
||||
DataColumn(label: Text('Calories'), numeric: true),
|
||||
DataColumn(label: Text('Generation')),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
expect(find.byType(Table), findsOneWidget);
|
||||
final Table table = tester.widget(find.byType(Table));
|
||||
final TableRow tableRow = table.children[0];
|
||||
final BoxDecoration? tableRowBoxDecoration = tableRow.decoration as BoxDecoration?;
|
||||
expect(tableRowBoxDecoration, isNotNull);
|
||||
expect(tableRowBoxDecoration?.border, isA<Border>());
|
||||
|
||||
final Border? border = tableRowBoxDecoration?.border as Border?;
|
||||
expect(border?.bottom.width, defaultDividerThickness);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user