Unverified Commit 88ded730 authored by Markus Aksli's avatar Markus Aksli Committed by GitHub

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

parent 0f24741a
......@@ -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,
......
......@@ -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(
......
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