added option to change color of heading row(flutter#132428) (#132728)

Paginated datatable widget cannot give color to table header
 
fixes #132428

---------

Co-authored-by: Hans Muller <hansmuller@google.com>
This commit is contained in:
Salmanul Farisi.M 2023-08-28 21:21:56 +05:30 committed by GitHub
parent 2ea5296616
commit 69f61a289e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import 'icon_button.dart';
import 'icons.dart';
import 'ink_decoration.dart';
import 'material_localizations.dart';
import 'material_state.dart';
import 'progress_indicator.dart';
import 'theme.dart';
@ -114,6 +115,7 @@ class PaginatedDataTable extends StatefulWidget {
this.checkboxHorizontalMargin,
this.controller,
this.primary,
this.headingRowColor,
}) : assert(actions == null || (header != null)),
assert(columns.isNotEmpty),
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
@ -288,6 +290,9 @@ class PaginatedDataTable extends StatefulWidget {
/// {@macro flutter.widgets.scroll_view.primary}
final bool? primary;
/// {@macro flutter.material.dataTable.headingRowColor}
final MaterialStateProperty<Color?>? headingRowColor;
@override
PaginatedDataTableState createState() => PaginatedDataTableState();
}
@ -595,6 +600,7 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
showCheckboxColumn: widget.showCheckboxColumn,
showBottomBorder: true,
rows: _getRows(_firstRowIndex, widget.rowsPerPage),
headingRowColor: widget.headingRowColor,
),
),
),

View File

@ -1264,4 +1264,33 @@ void main() {
final Scrollable footerScrollView = tester.widget(find.byType(Scrollable).last);
expect(footerScrollView.controller, null);
});
testWidgets('PaginatedDataTable custom heading row color', (WidgetTester tester) async {
const MaterialStateProperty<Color> headingRowColor = MaterialStatePropertyAll<Color>(Color(0xffFF0000));
final TestDataSource source = TestDataSource();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PaginatedDataTable(
primary: true,
header: const Text('Test table'),
source: source,
rowsPerPage: 2,
headingRowColor: headingRowColor,
columns: const <DataColumn>[
DataColumn(label: Text('Name')),
DataColumn(label: Text('Calories'), numeric: true),
DataColumn(label: Text('Generation')),
],
),
),
)
);
final Table table = tester.widget(find.byType(Table));
final TableRow tableRow = table.children[0];
final BoxDecoration tableRowBoxDecoration = tableRow.decoration! as BoxDecoration;
expect(tableRowBoxDecoration.color, headingRowColor.resolve(<MaterialState>{}));
});
}