findCaretRectInViewport static method
Finds and returns the bounding rectangle for the caret in the given SuperTextField, represented as coordinates that are local to the viewport.
The viewport is the rectangle within which (possibly) scrollable text is displayed.
By default, this method expects a single SuperTextField in the widget tree and
finds it byType. To specify one SuperTextField among many, pass a superTextFieldFinder.
Implementation
static Rect? findCaretRectInViewport([Finder? superTextFieldFinder]) {
final rootFieldFinder = superTextFieldFinder ?? find.byType(SuperTextField);
final desktopTextField = find.descendant(of: rootFieldFinder, matching: find.byType(SuperDesktopTextField));
if (desktopTextField.evaluate().isNotEmpty) {
return _findCaretRectInViewportOnDesktop(desktopTextField);
}
final iOSTextField = find.descendant(of: rootFieldFinder, matching: find.byType(SuperIOSTextField));
if (iOSTextField.evaluate().isNotEmpty) {
return _findCaretRectInViewportOnMobile(iOSTextField);
}
final androidTextField = find.descendant(of: rootFieldFinder, matching: find.byType(SuperAndroidTextField));
if (androidTextField.evaluate().isNotEmpty) {
return _findCaretRectInViewportOnMobile(androidTextField);
}
throw Exception(
"Couldn't find the caret rectangle because we couldn't find a SuperTextField. Finder: $superTextFieldFinder");
}