diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index a7ed565f3a15..fe03482e27f8 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -857,7 +857,7 @@ class DataTable extends StatelessWidget { height: effectiveHeadingRowHeight, alignment: numeric ? Alignment.centerRight : AlignmentDirectional.centerStart, child: AnimatedDefaultTextStyle( - style: effectiveHeadingTextStyle, + style: DefaultTextStyle.of(context).style.merge(effectiveHeadingTextStyle), softWrap: false, duration: _sortArrowAnimationDuration, child: label, @@ -926,9 +926,9 @@ class DataTable extends StatelessWidget { constraints: BoxConstraints(minHeight: effectiveDataRowMinHeight, maxHeight: effectiveDataRowMaxHeight), alignment: numeric ? Alignment.centerRight : AlignmentDirectional.centerStart, child: DefaultTextStyle( - style: effectiveDataTextStyle.copyWith( - color: placeholder ? effectiveDataTextStyle.color!.withOpacity(0.6) : null, - ), + style: DefaultTextStyle.of(context).style + .merge(effectiveDataTextStyle) + .copyWith(color: placeholder ? effectiveDataTextStyle.color!.withOpacity(0.6) : null), child: DropdownButtonHideUnderline(child: label), ), ); diff --git a/packages/flutter/test/material/data_table_test.dart b/packages/flutter/test/material/data_table_test.dart index fed5e1a04dac..fc738b73a63e 100644 --- a/packages/flutter/test/material/data_table_test.dart +++ b/packages/flutter/test/material/data_table_test.dart @@ -2279,4 +2279,46 @@ void main() { // Test that cursor is updated for the row. expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.copy); }); + + // This is a regression test for https://github.com/flutter/flutter/issues/114470. + testWidgetsWithLeakTracking('DataTable text styles are merged with default text style', (WidgetTester tester) async { + late DefaultTextStyle defaultTextStyle; + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Builder( + builder: (BuildContext context) { + defaultTextStyle = DefaultTextStyle.of(context); + return DataTable( + headingTextStyle: const TextStyle(), + dataTextStyle: const TextStyle(), + columns: const [ + DataColumn(label: Text('Header 1')), + DataColumn(label: Text('Header 2')), + ], + rows: const [ + DataRow( + cells: [ + DataCell(Text('Data 1')), + DataCell(Text('Data 2')), + ], + ), + ], + ); + } + ), + ), + ), + ); + + final TextStyle? headingTextStyle = _getTextRenderObject(tester, 'Header 1').text.style; + expect(headingTextStyle, defaultTextStyle.style); + + final TextStyle? dataTextStyle = _getTextRenderObject(tester, 'Data 1').text.style; + expect(dataTextStyle, defaultTextStyle.style); + }); +} + +RenderParagraph _getTextRenderObject(WidgetTester tester, String text) { + return tester.renderObject(find.text(text)); }