Make sure that a RefreshIndicator doesn't crash in 0x0 environment#177644
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a test to prevent a regression for issue #6537, where RefreshIndicator could crash in a zero-sized environment. The test correctly sets up this scenario.
My review identifies that the test is incomplete as it doesn't trigger the scrolling behavior that could cause the crash. I've provided suggestions to add a drag gesture simulation to the test and to make the ListView scrollable, making the test more comprehensive and robust for catching this kind of regression.
| ), | ||
| ), | ||
| ); | ||
| expect(tester.getSize(find.byType(RefreshIndicator)), Size.zero); |
There was a problem hiding this comment.
The current test only verifies that the widget can be pumped without crashing. To properly test for the crash described in issue #6537, which occurs during a scroll, a drag gesture should be simulated. This will trigger the code path that could cause a crash and ensure the fix is effective.
expect(tester.getSize(find.byType(RefreshIndicator)), Size.zero);
// Drag to trigger a scroll notification to test the drag behavior in a
// zero-sized environment, which could cause a crash.
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Center)));
await gesture.moveBy(const Offset(0.0, 20.0));
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();| child: SizedBox.shrink( | ||
| child: RefreshIndicator( | ||
| onRefresh: refresh, | ||
| child: ListView(children: const <Text>[Text('X')]), |
There was a problem hiding this comment.
To ensure the ListView is scrollable even when its content fits within its (zero-sized) viewport, you should add physics: const AlwaysScrollableScrollPhysics(). This makes the test more robust for triggering scroll notifications.
| child: ListView(children: const <Text>[Text('X')]), | |
| child: ListView(physics: const AlwaysScrollableScrollPhysics(), children: const <Text>[Text('X')]), |
dkwingsmt
left a comment
There was a problem hiding this comment.
LGTM. (I'm a bit surprised that this would work!)
|
autosubmit label was removed for flutter/flutter/177644, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
…lutter#177644) This is my attempt to handle flutter#6537 for the RefreshIndicator widget. --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com> Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
…lutter#177644) This is my attempt to handle flutter#6537 for the RefreshIndicator widget. --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com> Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
…lutter#177644) This is my attempt to handle flutter#6537 for the RefreshIndicator widget. --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com> Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This is my attempt to handle #6537 for the RefreshIndicator widget.