From 88800084522a89b54ae043740fd1db570455a8f0 Mon Sep 17 00:00:00 2001 From: Dheeraj Verma <40259140+dheerajv09@users.noreply.github.com> Date: Mon, 1 Nov 2021 21:38:05 +0530 Subject: [PATCH] Update Data Table Class with Borders Like Table Widgets (#36837) (#92670) --- .../flutter/lib/src/material/data_table.dart | 5 ++ .../test/material/data_table_test.dart | 65 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index becd51d923..4aa24900d7 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -391,6 +391,7 @@ class DataTable extends StatelessWidget { this.dividerThickness, required this.rows, this.checkboxHorizontalMargin, + this.border, }) : assert(columns != null), assert(columns.isNotEmpty), assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)), @@ -615,6 +616,9 @@ class DataTable extends StatelessWidget { /// and the content in the first data column. This value defaults to 24.0. final double? checkboxHorizontalMargin; + /// The style to use when painting the boundary and interior divisions of the table. + final TableBorder? border; + // Set by the constructor to the index of the only Column that is // non-numeric, if there is exactly one, otherwise null. final int? _onlyTextColumn; @@ -1022,6 +1026,7 @@ class DataTable extends StatelessWidget { child: Table( columnWidths: tableColumns.asMap(), children: tableRows, + border: border, ), ), ); diff --git a/packages/flutter/test/material/data_table_test.dart b/packages/flutter/test/material/data_table_test.dart index 3353a4ea3d..6858a96037 100644 --- a/packages/flutter/test/material/data_table_test.dart +++ b/packages/flutter/test/material/data_table_test.dart @@ -1670,4 +1670,69 @@ void main() { expect(find.widgetWithText(TableRowInkWell, 'Bug'), findsNothing); expect(find.widgetWithText(TableRowInkWell, 'GitHub'), findsNothing); }); + + testWidgets('DataTable set interior border test', (WidgetTester tester) async { + const List columns = [ + DataColumn(label: Text('column1')), + DataColumn(label: Text('column2')), + ]; + + const List cells = [ + DataCell(Text('cell1')), + DataCell(Text('cell2')), + ]; + + const List rows = [ + DataRow(cells: cells), + DataRow(cells: cells), + ]; + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: DataTable( + border: TableBorder.all(width: 2, color: Colors.red), + columns: columns, + rows: rows, + ), + ), + ), + ); + + final Finder finder = find.byType(DataTable); + expect(tester.getSize(finder), equals(const Size(800, 600))); + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: DataTable( + border: TableBorder.all(color: Colors.red), + columns: columns, + rows: rows, + ), + ), + ), + ); + + Table table = tester.widget(find.byType(Table)); + TableBorder? tableBorder = table.border; + expect(tableBorder!.top.color, Colors.red); + expect(tableBorder.bottom.width, 1); + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: DataTable( + columns: columns, + rows: rows, + ), + ), + ), + ); + + table = tester.widget(find.byType(Table)); + tableBorder = table.border; + expect(tableBorder?.bottom.width, null); + expect(tableBorder?.top.color, null); + }); }