You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, act.tap() taps the center of the RenderObject. But RenderParagraph can give the exact location of the text and there should be clicked, allowing TextSpans with gesture recognizers.
OffsetlocationOfTextSpan(String text) {
assert(text.length >1);
final paragraph =spotText(text).snapshotRenderObject() asRenderParagraph;
final fullText = paragraph.text.toPlainText();
final start = fullText.indexOf(text);
final end = start + text.length;
final barLocationStart =
paragraph.getOffsetForCaret(TextPosition(offset: start), Rect.zero);
final barLocationEnd =
paragraph.getOffsetForCaret(TextPosition(offset: end), Rect.zero);
if (barLocationStart.dy == barLocationEnd.dy) {
// on same line, click the middlereturnOffset(
(barLocationStart.dx + barLocationEnd.dx) /2,
(barLocationStart.dy + barLocationEnd.dy) /2,
);
} else {
// click one pixel inside the first characterreturn barLocationStart +constOffset(1, 1);
}
}
Future<void> tapTextSpan(String text) async {
final spanLocation =locationOfTextSpan(text);
final binding =TestWidgetsFlutterBinding.instance;
final downEvent =PointerDownEvent(position: spanLocation);
binding.handlePointerEvent(downEvent);
final upEvent =PointerUpEvent(position: spanLocation);
binding.handlePointerEvent(upEvent);
}
Currently, act.tap() taps the center of the RenderObject. But
RenderParagraph
can give the exact location of the text and there should be clicked, allowing TextSpans with gesture recognizers.This example should be the default
The text was updated successfully, but these errors were encountered: