首页 > 解决方案 > SemanticsService.announce 在颤振中

问题描述

正在浏览一个颤振库的代码,发现它正在被使用

SemanticsService.announce(
            localizations.formatMonthYear(_selectedFirstDate), textDirection);

做了谷歌搜索并阅读了颤振文档,但仍然不确定这是做什么的。任何人都可以向我解释这一点或指向一些涵盖这一点的资源吗?

标签: flutter

解决方案


这是关于可访问性。你可以看看,该方法的作用:

     /// Sends a semantic announcement.
  ///
  /// This should be used for announcement that are not seamlessly announced by
  /// the system as a result of a UI state change.
  ///
  /// For example a camera application can use this method to make accessibility
  /// announcements regarding objects in the viewfinder.
  static Future<void> announce(String message, TextDirection textDirection) async {
    final AnnounceSemanticsEvent event = AnnounceSemanticsEvent(message, textDirection);
    await SystemChannels.accessibility.send(event.toMap());
  }

所以基本上屏幕阅读器(VoiceOver / Talkback)会读出消息参数中传递的内容。


推荐阅读