Fix DataTable _SortArrow changing orientation when state is updated (#94455)

This commit is contained in:
Markus Aksli 2022-01-06 00:10:17 +02:00 committed by GitHub
parent 0f24741abd
commit 88ded73061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 0 deletions

View File

@ -1139,6 +1139,7 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
@override
void initState() {
super.initState();
_up = widget.up;
_opacityAnimation = CurvedAnimation(
parent: _opacityController = AnimationController(
duration: widget.duration,

View File

@ -486,6 +486,105 @@ void main() {
);
});
testWidgets('DataTable sort indicator orientation does not change on state update', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/43724
Widget buildTable({String title = 'Name1'}) {
return DataTable(
sortColumnIndex: 0,
columns: <DataColumn>[
DataColumn(
label: Text(title),
tooltip: 'Name',
onSort: (int columnIndex, bool ascending) {},
),
],
rows: kDesserts.map<DataRow>((Dessert dessert) {
return DataRow(
cells: <DataCell>[
DataCell(
Text(dessert.name),
),
],
);
}).toList(),
);
}
// Check for ascending list
await tester.pumpWidget(MaterialApp(
home: Material(child: buildTable()),
));
// The `tester.widget` ensures that there is exactly one upward arrow.
final Finder iconFinder = find.widgetWithIcon(Transform, Icons.arrow_upward);
Transform transformOfArrow = tester.widget<Transform>(iconFinder);
expect(
transformOfArrow.transform.getRotation(),
equals(Matrix3.identity()),
);
// Cause a rebuild by updating the widget
await tester.pumpWidget(MaterialApp(
home: Material(child: buildTable(title: 'Name2')),
));
await tester.pumpAndSettle();
// The `tester.widget` ensures that there is exactly one upward arrow.
transformOfArrow = tester.widget<Transform>(iconFinder);
expect(
transformOfArrow.transform.getRotation(),
equals(Matrix3.identity()), // Should not have changed
);
});
testWidgets('DataTable sort indicator orientation does not change on state update - reverse', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/43724
Widget buildTable({String title = 'Name1'}) {
return DataTable(
sortColumnIndex: 0,
sortAscending: false,
columns: <DataColumn>[
DataColumn(
label: Text(title),
tooltip: 'Name',
onSort: (int columnIndex, bool ascending) {},
),
],
rows: kDesserts.map<DataRow>((Dessert dessert) {
return DataRow(
cells: <DataCell>[
DataCell(
Text(dessert.name),
),
],
);
}).toList(),
);
}
// Check for ascending list
await tester.pumpWidget(MaterialApp(
home: Material(child: buildTable()),
));
// The `tester.widget` ensures that there is exactly one upward arrow.
final Finder iconFinder = find.widgetWithIcon(Transform, Icons.arrow_upward);
Transform transformOfArrow = tester.widget<Transform>(iconFinder);
expect(
transformOfArrow.transform.getRotation(),
equals(Matrix3.rotationZ(math.pi)),
);
// Cause a rebuild by updating the widget
await tester.pumpWidget(MaterialApp(
home: Material(child: buildTable(title: 'Name2')),
));
await tester.pumpAndSettle();
// The `tester.widget` ensures that there is exactly one upward arrow.
transformOfArrow = tester.widget<Transform>(iconFinder);
expect(
transformOfArrow.transform.getRotation(),
equals(Matrix3.rotationZ(math.pi)), // Should not have changed
);
});
testWidgets('DataTable row onSelectChanged test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(