tap method

Future<void> tap(
  1. Finder finder, {
  2. SettlePolicy? settlePolicy,
  3. Duration? visibleTimeout,
  4. Duration? settleTimeout,
  5. Alignment alignment = Alignment.center,
  6. bool enablePatrolLog = true,
})

Waits until this finder finds at least 1 visible widget and then taps on it.

Example:

// taps on the first widget having Key('createAccount')
await $(#createAccount).tap();

If the finder finds more than 1 widget, you can choose which one to tap on:

// taps on the third TextButton widget
await $(TextButton).at(2).tap();

This method automatically calls WidgetTester.pumpAndSettle after tapping. If you want to disable this behavior, set settlePolicy to SettlePolicy.noSettle.

See also:

Implementation

Future<void> tap(
  Finder finder, {
  SettlePolicy? settlePolicy,
  Duration? visibleTimeout,
  Duration? settleTimeout,
  Alignment alignment = Alignment.center,
  bool enablePatrolLog = true,
}) {
  return TestAsyncUtils.guard(
    () => wrapWithPatrolLog(
      action: 'tap',
      finder: finder,
      color: AnsiCodes.yellow,
      enablePatrolLog: enablePatrolLog,
      function: () async {
        final resolvedFinder = await waitUntilVisible(
          finder,
          timeout: visibleTimeout,
          alignment: alignment,
          enablePatrolLog: false,
        );
        final rect = tester.getRect(resolvedFinder.first);
        await tester.tapAt(alignment.withinRect(rect));
        await _performPump(
          settlePolicy: settlePolicy,
          settleTimeout: settleTimeout,
        );
      },
    ),
  );
}