Skip to content

[Docs]Tests to scroll a ListView and tap on a child #88762

Description

@mleonhard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsd: api docsIssues with https://api.flutter.dev/f: integration_testThe flutter/packages/integration_test pluginframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions