如何强制屏幕 reader 在 Flutter 中说些什么?

How to enforce the screen reader to say something in Flutter?

我正在处理 Flutter 中的辅助功能,并希望在不使用小部件的情况下让声音 reader 向用户说些什么。

怎么做?

您可以为其使用语义服务:

SemanticsService.announce('I am saying something', TextDirection.ltr);
    static Future<void> announce(String message, TextDirection textDirection) async {
  final AnnounceSemanticsEvent event = AnnounceSemanticsEvent(message, textDirection);
  await SystemChannels.accessibility.send(event.toMap());
}

announce 是 SemanticsService 的方法 class 您可以按照下面的代码使用它

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: RaisedButton(
          child: Text("Press me"),
          onPressed: () {
            SemanticsService.announce(
                "I've just been pressed", TextDirection.ltr);
          },
        ),
      ),
    );
  }
}

检查文档https://api.flutter.dev/flutter/semantics/SemanticsService/announce.html