Unverified Commit 941897f6 authored by Aakash Pamnani's avatar Aakash Pamnani Committed by GitHub

Fixed : Empty Rows shown at last page in Paginated data table (#132646)

Fixed empty rows at the last page in paginated data table

BEFORE:
![Before](https://github.com/flutter/flutter/assets/76067278/1f1e364c-df38-462f-b9fb-868554ce04a5)

AFTER:
![After](https://github.com/flutter/flutter/assets/76067278/80648a25-e9e6-4873-805f-b18c7c6a00af)

Issues resolves : #80421
parent 8e4292b1
......@@ -112,6 +112,7 @@ class PaginatedDataTable extends StatefulWidget {
this.controller,
this.primary,
this.headingRowColor,
this.showEmptyRows = true,
}) : assert(actions == null || (header != null)),
assert(columns.isNotEmpty),
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
......@@ -289,6 +290,14 @@ class PaginatedDataTable extends StatefulWidget {
/// {@macro flutter.material.dataTable.headingRowColor}
final MaterialStateProperty<Color?>? headingRowColor;
/// Controls the visibility of empty rows on the last page of a
/// [PaginatedDataTable].
///
/// Defaults to `true`, which means empty rows will be populated on the
/// last page of the table if there is not enough content.
/// When set to `false`, empty rows will not be created.
final bool showEmptyRows;
@override
PaginatedDataTableState createState() => PaginatedDataTableState();
}
......@@ -407,8 +416,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
haveProgressIndicator = true;
}
}
row ??= _getBlankRowFor(index);
result.add(row);
if (widget.showEmptyRows) {
row ??= _getBlankRowFor(index);
}
if (row != null) {
result.add(row);
}
}
return result;
}
......@@ -600,6 +615,9 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
),
),
),
if (!widget.showEmptyRows)
SizedBox(
height: (widget.dataRowMaxHeight ?? kMinInteractiveDimension) * (widget.rowsPerPage - _rowCount + _firstRowIndex).clamp(0, widget.rowsPerPage)), // ignore_clamp_double_lint
DefaultTextStyle(
style: footerTextStyle!,
child: IconTheme.merge(
......
......@@ -303,6 +303,83 @@ void main() {
expect(find.text('497–500 of 500'), findsOneWidget);
});
testWidgetsWithLeakTracking('PaginatedDataTable Last Page Empty Space', (WidgetTester tester) async {
final TestDataSource source = TestDataSource();
int rowsPerPage = 3;
final int rowCount = source.rowCount;
addTearDown(source.dispose);
Widget buildTable(TestDataSource source, int rowsPerPage) {
return PaginatedDataTable(
header: const Text('Test table'),
source: source,
rowsPerPage: rowsPerPage,
showFirstLastButtons: true,
dataRowHeight: 46,
availableRowsPerPage: const <int>[
3, 6, 7, 8, 9,
],
onRowsPerPageChanged: (int? rowsPerPage) {
},
onPageChanged: (int rowIndex) {
},
columns: const <DataColumn>[
DataColumn(label: Text('Name')),
DataColumn(label: Text('Calories'), numeric: true),
DataColumn(label: Text('Generation')),
],
showEmptyRows: false,
);
}
await tester.pumpWidget(MaterialApp(
home: Scaffold(body: Center(child: buildTable(source, rowsPerPage)))
));
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == 0), findsOneWidget);
await tester.tap(find.byIcon(Icons.skip_next));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == (rowsPerPage - (rowCount % rowsPerPage)) * 46.0), findsOneWidget);
rowsPerPage = 6;
await tester.pumpWidget(MaterialApp(
home: buildTable(source, rowsPerPage)
));
await tester.tap(find.byIcon(Icons.skip_previous));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == 0), findsOneWidget);
await tester.tap(find.byIcon(Icons.skip_next));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == (rowsPerPage - (rowCount % rowsPerPage)) * 46.0), findsOneWidget);
rowsPerPage = 7;
await tester.pumpWidget(MaterialApp(
home: buildTable(source, rowsPerPage)
));
await tester.tap(find.byIcon(Icons.skip_previous));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == 0), findsOneWidget);
await tester.tap(find.byIcon(Icons.skip_next));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == (rowsPerPage - (rowCount % rowsPerPage)) * 46.0), findsOneWidget);
rowsPerPage = 8;
await tester.pumpWidget(MaterialApp(
home: buildTable(source, rowsPerPage)
));
await tester.tap(find.byIcon(Icons.skip_previous));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == 0), findsOneWidget);
await tester.tap(find.byIcon(Icons.skip_next));
await tester.pump();
expect(find.byWidgetPredicate((Widget widget) => widget is SizedBox && widget.height == (rowsPerPage - (rowCount % rowsPerPage)) * 46.0), findsOneWidget);
});
testWidgetsWithLeakTracking('PaginatedDataTable control test', (WidgetTester tester) async {
TestDataSource source = TestDataSource()
..generation = 42;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment