diff --git a/packages/flutter/lib/src/material/paginated_data_table.dart b/packages/flutter/lib/src/material/paginated_data_table.dart index a1f2fde6d3..42dd4b9a57 100644 --- a/packages/flutter/lib/src/material/paginated_data_table.dart +++ b/packages/flutter/lib/src/material/paginated_data_table.dart @@ -7,7 +7,6 @@ import 'dart:math' as math; import 'package:flutter/gestures.dart' show DragStartBehavior; import 'package:flutter/widgets.dart'; -import 'button_bar.dart'; import 'card.dart'; import 'constants.dart'; import 'data_table.dart'; @@ -372,17 +371,8 @@ class PaginatedDataTableState extends State { final MaterialLocalizations localizations = MaterialLocalizations.of(context); // HEADER final List headerWidgets = []; - double startPadding = 24.0; if (_selectedRowCount == 0 && widget.header != null) { headerWidgets.add(Expanded(child: widget.header!)); - if (widget.header is ButtonBar) { - // We adjust the padding when a button bar is present, because the - // ButtonBar introduces 2 pixels of outside padding, plus 2 pixels - // around each button on each side, and the button itself will have 8 - // pixels internally on each side, yet we want the left edge of the - // inside of the button to line up with the 24.0 left inset. - startPadding = 12.0; - } } else if (widget.header != null) { headerWidgets.add(Expanded( child: Text(localizations.selectedRowCountTitle(_selectedRowCount)), @@ -501,7 +491,7 @@ class PaginatedDataTableState extends State { height: 64.0, color: _selectedRowCount > 0 ? themeData.secondaryHeaderColor : null, child: Padding( - padding: EdgeInsetsDirectional.only(start: startPadding, end: 14.0), + padding: const EdgeInsetsDirectional.only(start: 24, end: 14.0), child: Row( mainAxisAlignment: MainAxisAlignment.end, children: headerWidgets, diff --git a/packages/flutter/test/material/paginated_data_table_test.dart b/packages/flutter/test/material/paginated_data_table_test.dart index 9dc12e3b13..faf0d1c052 100644 --- a/packages/flutter/test/material/paginated_data_table_test.dart +++ b/packages/flutter/test/material/paginated_data_table_test.dart @@ -1012,4 +1012,32 @@ void main() { expect(icons.elementAt(2).color, arrowHeadColor); expect(icons.elementAt(3).color, arrowHeadColor); }); + + testWidgets('OverflowBar header left alignment', (WidgetTester tester) async { + // Test an old special case that tried to align the first child of a ButtonBar + // and the left edge of a Text header widget. Still possible with OverflowBar + // albeit without any special case in the implementation's build method. + Widget buildFrame(Widget header) { + return MaterialApp( + home: PaginatedDataTable( + header: header, + rowsPerPage: 2, + source: TestDataSource(), + columns: const [ + DataColumn(label: Text('Name')), + DataColumn(label: Text('Calories'), numeric: true), + DataColumn(label: Text('Generation')), + ], + ), + ); + } + + await tester.pumpWidget(buildFrame(const Text('HEADER'))); + final double headerX = tester.getTopLeft(find.text('HEADER')).dx; + final Widget overflowBar = OverflowBar( + children: [ElevatedButton(onPressed: () {}, child: const Text('BUTTON'))], + ); + await tester.pumpWidget(buildFrame(overflowBar)); + expect(headerX, tester.getTopLeft(find.byType(ElevatedButton)).dx); + }); }