enterText method
Future<void>
enterText(
- Finder finder,
- String text, {
- SettlePolicy? settlePolicy,
- Duration? visibleTimeout,
- Duration? settleTimeout,
Waits until finder
finds at least 1 visible widget and then enters text
into it.
Example:
// enters text into the first widget having Key('email')
await $(#email).enterText(user@example.com);
If the finder finds more than 1 widget, you can choose which one to enter text into:
// enters text into the third TextField widget
await $(TextField).at(2).enterText('Code ought to be lean');
This method automatically calls WidgetTester.pumpAndSettle after
entering text. If you want to disable this behavior, set settlePolicy
to
SettlePolicy.noSettle.
See also:
- PatrolFinder.waitUntilVisible, which is used to wait for the widget to appear
- WidgetTester.enterText
Implementation
Future<void> enterText(
Finder finder,
String text, {
SettlePolicy? settlePolicy,
Duration? visibleTimeout,
Duration? settleTimeout,
}) {
if (!kIsWeb) {
// Fix for enterText() not working in release mode on real iOS devices.
// See https://github.com/flutter/flutter/pull/89703
// Also a fix for enterText() not being able to interact with the same
// textfield 2 times in the same test.
// See https://github.com/flutter/flutter/issues/134604
tester.testTextInput.register();
}
return TestAsyncUtils.guard(() async {
final resolvedFinder = await waitUntilVisible(
finder,
timeout: visibleTimeout,
);
await tester.enterText(resolvedFinder.first, text);
await _performPump(
settlePolicy: settlePolicy,
settleTimeout: settleTimeout,
);
});
}