enterText to move the caret to the end (#79506)

This commit is contained in:
LongCatIsLooong
2021-04-01 20:29:03 -07:00
committed by GitHub
parent fb68d07477
commit 67d8556baa
4 changed files with 60 additions and 17 deletions

View File

@@ -166,10 +166,14 @@ class TestTextInput {
}
/// Simulates the user typing the given text.
///
/// Calling this method replaces the content of the connected input field with
/// `text`, and places the caret at the end of the text.
void enterText(String text) {
assert(isRegistered);
updateEditingValue(TextEditingValue(
text: text,
selection: TextSelection.collapsed(offset: text.length),
));
}

View File

@@ -1040,13 +1040,16 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
});
}
/// Give the text input widget specified by [finder] the focus and
/// enter [text] as if it been provided by the onscreen keyboard.
/// Give the text input widget specified by [finder] the focus and replace its
/// content with [text], as if it had been provided by the onscreen keyboard.
///
/// The widget specified by [finder] must be an [EditableText] or have
/// an [EditableText] descendant. For example `find.byType(TextField)`
/// or `find.byType(TextFormField)`, or `find.byType(EditableText)`.
///
/// When the returned future completes, the text input widget's text will be
/// exactly `text`, and the caret will be placed at the end of `text`.
///
/// To just give [finder] the focus without entering any text,
/// see [showKeyboard].
Future<void> enterText(Finder finder, String text) async {