Skip to content

WidgetTester.ensureVisible() to stop ignoring failure #88763

Description

@mleonhard

Use case

I'm writing an integration test for a mobile app. I tried using WidgetTester.ensureVisible() (inherited from WidgetController.ensureVisible) to scroll a widget into the viewport and then tap() it.

The scroll operation failed (#88762) and ensureVisible() failed to move the widget entirely onto the screen. It silently ignored this error. Then I wasted time trying to figure out why the subsequent tap() call failed (which also silently failed #88759).

I'm surprised to find a library from Google that silently ignores errors. I think future Flutter users would benefit from a WidgetTester rewrite that follows modern software engineering practices like "fail fast" and "fail with a useful error message". CC: @timsneath

Proposal

  1. Rename ensureVisible() to tryEnsureVisible() and make it return true if it moved the widget onto the screen.
  2. Add a new ensureVisible() method that immediately fails the test if it cannot move the widget onto the screen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our testsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: 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