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

Viewed 514

I am working with accessibility in Flutter and want to make the voice reader to say something to the user without the use of widgets for it.

How to do it?

2 Answers
    static Future<void> announce(String message, TextDirection textDirection) async {
  final AnnounceSemanticsEvent event = AnnounceSemanticsEvent(message, textDirection);
  await SystemChannels.accessibility.send(event.toMap());
}

announce is method of SemanticsService class Which you can use as per below code

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);
          },
        ),
      ),
    );
  }
}

Check Documentation https://api.flutter.dev/flutter/semantics/SemanticsService/announce.html

You can use the SemanticsService for it:

SemanticsService.announce('I am saying something', TextDirection.ltr);
Related