diff --git a/packages/flutter/lib/src/material/paginated_data_table.dart b/packages/flutter/lib/src/material/paginated_data_table.dart index 30ac1bd6c4..10148b9c2d 100644 --- a/packages/flutter/lib/src/material/paginated_data_table.dart +++ b/packages/flutter/lib/src/material/paginated_data_table.dart @@ -61,6 +61,10 @@ class PaginatedDataTable extends StatefulWidget { /// /// The [rowsPerPage] and [availableRowsPerPage] must not be null (they /// both have defaults, though, so don't have to be specified). + /// + /// Themed by [DataTableTheme]. [DataTableThemeData.decoration] is ignored. + /// To modify the border or background color of the [PaginatedDataTable], use + /// [CardTheme], since a [Card] wraps the inner [DataTable]. PaginatedDataTable({ Key? key, this.header, @@ -471,6 +475,9 @@ class PaginatedDataTableState extends State { sortColumnIndex: widget.sortColumnIndex, sortAscending: widget.sortAscending, onSelectAll: widget.onSelectAll, + // Make sure no decoration is set on the DataTable + // from the theme, as its already wrapped in a Card. + decoration: const BoxDecoration(), dataRowHeight: widget.dataRowHeight, headingRowHeight: widget.headingRowHeight, horizontalMargin: widget.horizontalMargin, diff --git a/packages/flutter/test/material/paginated_data_table_test.dart b/packages/flutter/test/material/paginated_data_table_test.dart index 1ed040683e..317171a51f 100644 --- a/packages/flutter/test/material/paginated_data_table_test.dart +++ b/packages/flutter/test/material/paginated_data_table_test.dart @@ -786,4 +786,36 @@ void main() { await tester.pumpWidget(buildTable(false)); expect(find.byType(Checkbox), findsNothing); }); + + testWidgets('Table should not use decoration from DataTableTheme', (WidgetTester tester) async { + final Size originalSize = binding.renderView.size; + await binding.setSurfaceSize(const Size(800, 800)); + + Widget buildTable() { + return MaterialApp( + theme: ThemeData.light().copyWith( + dataTableTheme: const DataTableThemeData( + decoration: BoxDecoration(color: Colors.white), + ), + ), + home: PaginatedDataTable( + header: const Text('Test table'), + source: TestDataSource(onSelectChanged: (bool? value) {}), + showCheckboxColumn: true, + columns: const [ + DataColumn(label: Text('Name')), + DataColumn(label: Text('Calories'), numeric: true), + DataColumn(label: Text('Generation')), + ], + ), + ); + } + + await tester.pumpWidget(buildTable()); + final Finder tableContainerFinder = find.ancestor(of: find.byType(Table), matching: find.byType(Container)).first; + expect(tester.widget(tableContainerFinder).decoration, const BoxDecoration()); + + // Reset the surface size. + await binding.setSurfaceSize(originalSize); + }); }