From 77f88ff78a6dae4d49471338fa67744ccd5d17c7 Mon Sep 17 00:00:00 2001 From: Emmanuel Bonke <55477248+Coder-Manuel@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:43:20 +0300 Subject: [PATCH] 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`. --- .../src/material/paginated_data_table.dart | 10 +++ .../material/paginated_data_table_test.dart | 61 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/packages/flutter/lib/src/material/paginated_data_table.dart b/packages/flutter/lib/src/material/paginated_data_table.dart index 971aee5dd5..06523ca034 100644 --- a/packages/flutter/lib/src/material/paginated_data_table.dart +++ b/packages/flutter/lib/src/material/paginated_data_table.dart @@ -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 { 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(), diff --git a/packages/flutter/test/material/paginated_data_table_test.dart b/packages/flutter/test/material/paginated_data_table_test.dart index d0f67a246b..b572a464ea 100644 --- a/packages/flutter/test/material/paginated_data_table_test.dart +++ b/packages/flutter/test/material/paginated_data_table_test.dart @@ -1413,4 +1413,65 @@ void main() { final BoxDecoration tableRowBoxDecoration = tableRow.decoration! as BoxDecoration; expect(tableRowBoxDecoration.color, headingRowColor.resolve({})); }); + + 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(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()); + + 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(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()); + + final Border? border = tableRowBoxDecoration?.border as Border?; + expect(border?.bottom.width, defaultDividerThickness); + }); }