Use case
I am developing a mobile app that uses a ListView with a static list of child widgets. I'm writing a test that must scroll the view and tap on a child widget.
One can use WidgetTester.scrollUntilVisible() (inherited from WidgetController.scrollUntilVisible) to scroll a parent widget repeatedly until a particular child is visible. The widget is now in view and being built, so one can call WidgetTester.ensureVisible() (inherited from WidgetController.ensureVisible) and scroll it completely into the viewport.
Unfortunately, both of those functions rely on the parent widget being Scrollable. Sadly, contrary to its documentation, ListView does NOT extend Scrollable. Even more sadly, Scrollable is not an interface that we could implement on a custom widget.
We can use WidgetTester.dragUntilVisible() (inherited from WidgetController.dragUntilVisible) to scroll the ListView. But there is no way to make sure that the center of the child widget is in the viewport so tap will succeed. There is no dragEnsureVisible().
I thought of some poor workarounds:
- Replace the
ListView with a Column inside a SingleChildScrollView. This will make the app heavier.
- Write my own
dragEnsureVisible() test function.
- Write my own
tap() that will tap on any visible part of the target.
Proposal
Provide a way to write a test that scrolls a ListView and taps on a child widget.
Use case
I am developing a mobile app that uses a
ListViewwith a static list of child widgets. I'm writing a test that must scroll the view and tap on a child widget.One can use
WidgetTester.scrollUntilVisible()(inherited fromWidgetController.scrollUntilVisible) to scroll a parent widget repeatedly until a particular child is visible. The widget is now in view and being built, so one can callWidgetTester.ensureVisible()(inherited fromWidgetController.ensureVisible) and scroll it completely into the viewport.Unfortunately, both of those functions rely on the parent widget being
Scrollable. Sadly, contrary to its documentation,ListViewdoes NOT extendScrollable. Even more sadly,Scrollableis not an interface that we could implement on a custom widget.We can use
WidgetTester.dragUntilVisible()(inherited fromWidgetController.dragUntilVisible) to scroll theListView. But there is no way to make sure that the center of the child widget is in the viewport sotapwill succeed. There is nodragEnsureVisible().I thought of some poor workarounds:
ListViewwith aColumninside aSingleChildScrollView. This will make the app heavier.dragEnsureVisible()test function.tap()that will tap on any visible part of the target.Proposal
Provide a way to write a test that scrolls a
ListViewand taps on a child widget.