0

Very new to flutter WidgetTest and could not find a solution to a problem I am having. When dealing with TextSpan objects for WidgetTests, I'm unable to tap on the object.

UI Code

RichText(
    text: TextSpan(
        text: "First piece of text",

        children: [
        TextSpan(
            text: "Text I want to tap in widget text",
            
            recognizer: TapGestureRecognizer()
                ..onTap = () {
                // go to another page i want to look for a text widget on
                }),
        ],
    ),
)

WidgetTest code

Future<void> textSpanTap(WidgetTester tester) async {
  await tester.pumpWidget(const MaterialApp(home: signInPage));
  await tester.tap(find.text("Text I want to tap in widget text"));
}

Any insight on this would help.

1 Answers1

0

Initially I started with the similar question here: Finding a TextSpan to tap on with Flutter tests .

But the solution from there proved to be non-reliable (worked, but for any configuration).

I ended up using the suggested workaround from here: https://github.com/flutter/flutter/issues/56023#issuecomment-764985456

mspnr
  • 416
  • 4
  • 12