1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter TextSpan has incorrect <href> when ensureSemantics is used to build default...

Discussão em 'Mobile' iniciado por Stack, Outubro 10, 2024 às 01:02.

  1. Stack

    Stack Membro Participativo

    I have a Flutter app that builds a Semantics tree by calling SemanticsBinding.instance.ensureSemantics(); on startup.

    When this is done, TextSpans with TapGestureRecognizers are being rendered in the Semantics tree with href='#' (see screenshot). When the user taps on these elements, the TapGestureRecognizer onTap method is invoked, but the app also incorrectly navigates to '#.' I cannot figure out how to change this behavior. I would rather not exclude semantics on these elements because I'd like them to be findable by automated tests. Help greatly appreciated.

    Example TextSpan

    Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    mainAxisSize: MainAxisSize.min,
    children: [
    Flexible(
    child: RichText(
    text: TextSpan(
    style: AppTextStyle.body.copyWith(color: AppColor.gray3),
    children: [
    TextSpan(text: subtitle),
    TextSpan(recognizer: TapGestureRecognizer()
    ..onTap = () => launch(learnMoreUrl),
    text: 'Learn More',
    style: AppTextStyle.body.copyWith(
    color: Colors.blue,
    decoration: TextDecoration.underline,
    ),
    ]),
    ),
    // etc




    The above code will launch a new tab and navigate to learnMoreUrl, then promptly navigate itself back to the home page.

    Element in the Semantics Tree: [​IMG]

    Continue reading...

Compartilhe esta Página