Flutter Semantics 在单击和双击时读取按钮标题

发布于 2025-01-18 00:02:45 字数 734 浏览 1 评论 0原文

我的UI中有一个工具提示,上面有语义标签“工具提示要了解您的电话”。以下是相同的代码段。

Semantics(
                              
                              label: 'Tooltip to know about your number',
                              child: InkWell(
                                child: Image.asset('images/info_selected.png'),
                                onTap: (){
                                  //some action top show tooltip
                                },
                              ),
                            ),

当访问性打开时,我单击了Info inf infunwell,它宣布“工具提示要了解您的电话号码”,如预期的。但是我在这里的问题,当我双击时,它也宣布相同。它只能执行我在double点击时在ontap函数中编写的功能。最佳的方法是什么,当我双击时,它不应该宣布?

相同的代码在Android中工作正常,只有在我单击时才宣布。只有iOS屏幕读取器在单点击和双击上都宣布标签

I have a tooltip in my UI which has semantics label "Tooltip to know about your number". Below is the code snippet for the same.

Semantics(
                              
                              label: 'Tooltip to know about your number',
                              child: InkWell(
                                child: Image.asset('images/info_selected.png'),
                                onTap: (){
                                  //some action top show tooltip
                                },
                              ),
                            ),

When accessibility is ON , and I single tap on info Inkwell, it announce "Tooltip to know about your number" as expected. But my issue here , Its also announcing the same when I double tap.. It should only do the functionality which I wrote inside onTap function when I double tap. What is the best way to make it like , it should not announce when I double tap?

Same code is working fine in android and it announce only when I single tap.. only iOS screen reader is announcing the label on both single tap and double tap..

Same issue when I use Gesture Detector or Button instead of InkWell..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走就滚别墨迹 2025-01-25 00:02:46

Inkwell具有onTaponDoubleTap两个功能可用

参考 - https://api.flutter.dev/flutter/material/material/inkwell-class.html

输出: -

​>代码: -

import 'package:flutter/material.dart';

class InkwellExample extends StatefulWidget {
  const InkwellExample({Key? key}) : super(key: key);

  @override
  State<InkwellExample> createState() => _InkwellExampleState();
}

class _InkwellExampleState extends State<InkwellExample> {
  String taps = "";

  @override
  Widget build(BuildContext context) {
    final Size size = MediaQuery.of(context).size;
    return Scaffold(
      body: SizedBox(
        width: size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            InkWell(
              child: const Icon(Icons.info),
              onTap: () => setState(() {
                taps = "TAP";
              }),
              onDoubleTap: () => setState(() {
                taps = "Double TAP";
              }),
            ),
            Text(
              taps == "" ? "" : taps,
              style: const TextStyle(
                fontSize: 24.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Inkwell have a onTap and onDoubleTap both functions available

Reference - https://api.flutter.dev/flutter/material/InkWell-class.html

Output :-

enter image description here

Code :-

import 'package:flutter/material.dart';

class InkwellExample extends StatefulWidget {
  const InkwellExample({Key? key}) : super(key: key);

  @override
  State<InkwellExample> createState() => _InkwellExampleState();
}

class _InkwellExampleState extends State<InkwellExample> {
  String taps = "";

  @override
  Widget build(BuildContext context) {
    final Size size = MediaQuery.of(context).size;
    return Scaffold(
      body: SizedBox(
        width: size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            InkWell(
              child: const Icon(Icons.info),
              onTap: () => setState(() {
                taps = "TAP";
              }),
              onDoubleTap: () => setState(() {
                taps = "Double TAP";
              }),
            ),
            Text(
              taps == "" ? "" : taps,
              style: const TextStyle(
                fontSize: 24.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
凑诗 2025-01-25 00:02:46

要阻止屏幕阅读器读取 label 参数中的内容以外的任何内容,请添加 excludeSemantics: true。因此,您的代码将如下所示:

Semantics(
  label: 'Tooltip to know about your number',
  excludeSemantics: true,
  child: InkWell(
    child: Image.asset('images/info_selected.png'),
    onTap: (){
      //some action top show tooltip
    },
  ),
),

另一个可能令人感兴趣的参数是 onTapHint

我用过的一个参考:
https://www.woolha.com/tutorials/flutter-using-语义-合并语义-示例

To keep screen readers from reading anything other than what you have in your label parameter, add excludeSemantics: true. So your code would look like this:

Semantics(
  label: 'Tooltip to know about your number',
  excludeSemantics: true,
  child: InkWell(
    child: Image.asset('images/info_selected.png'),
    onTap: (){
      //some action top show tooltip
    },
  ),
),

Another parameter which may be of interest is onTapHint.

One reference I've used:
https://www.woolha.com/tutorials/flutter-using-semantics-mergesemantics-examples

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文