Unverified Commit 60688913 authored by Amir Panahandeh's avatar Amir Panahandeh Committed by GitHub

Add stateful reordering test for TwoDimensionalViewport (#142375)

Adds a test to validate state is preserved after reordering in `TwoDimensionalViewport` (reference: https://github.com/flutter/flutter/pull/141504#pullrequestreview-1837501775).

- Fixes #130754
parent 203ec8b8
......@@ -2759,6 +2759,56 @@ void main() {
expect(tester.getRect(find.byKey(const ValueKey<int>(1))),
const Rect.fromLTWH(200.0, 200.0, 200.0, 200.0));
}, variant: TargetPlatformVariant.all());
testWidgets('state is preserved after reordering',
(WidgetTester tester) async {
final TwoDimensionalChildBuilderDelegate delegate1 =
TwoDimensionalChildBuilderDelegate(
maxXIndex: 5,
maxYIndex: 5,
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
builder: (BuildContext context, ChildVicinity vicinity) {
ValueKey<int>? key;
if (vicinity == const ChildVicinity(xIndex: 1, yIndex: 1)) {
key = const ValueKey<int>(1);
} else if (vicinity ==
const ChildVicinity(xIndex: 1, yIndex: 2)) {
key = const ValueKey<int>(2);
}
return Checkbox(key: key, value: false, onChanged: (_) {});
});
final TwoDimensionalChildBuilderDelegate delegate2 =
TwoDimensionalChildBuilderDelegate(
maxXIndex: 5,
maxYIndex: 5,
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
builder: (BuildContext context, ChildVicinity vicinity) {
ValueKey<int>? key;
if (vicinity == const ChildVicinity(xIndex: 0, yIndex: 0)) {
key = const ValueKey<int>(1);
} else if (vicinity ==
const ChildVicinity(xIndex: 1, yIndex: 1)) {
key = const ValueKey<int>(2);
}
return Checkbox(key: key, value: false, onChanged: (_) {});
});
addTearDown(delegate1.dispose);
addTearDown(delegate2.dispose);
await tester.pumpWidget(simpleBuilderTest(delegate: delegate1));
final State stateBeforeReordering =
tester.state(find.byKey(const ValueKey<int>(2)));
await tester.pumpWidget(simpleBuilderTest(delegate: delegate2));
expect(tester.state(find.byKey(const ValueKey<int>(2))),
stateBeforeReordering);
await tester.pumpWidget(simpleBuilderTest(delegate: delegate1));
expect(tester.state(find.byKey(const ValueKey<int>(2))),
stateBeforeReordering);
}, variant: TargetPlatformVariant.all());
});
}
......
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