How to check whether screen reader is on using Flutter

927

I was able to find out the answer by my self :)

here a sample code

void main(){
  runApp(MaterialApp(
    home: MyWidget(),
  ));
}

class MyWidget extends StatelessWidget {

  Widget build(BuildContext context) {
    // retrieve the mediaQuery data
    final mediaQueryData = MediaQuery.of(context);
    if (mediaQueryData.accessibleNavigation) {
      return Text('Screen reader is on');
    } else {
      return Text('Screen reader is off');
    }
  }

}

THANKS :)

Update:

I tested the code with enabling magnification and select-to-speak features.. but no change happened of the output. As It originated from accessibleNavigation property of [Window.AccessibilityFeatures],. It results whether there is a running accessibility service which is changing the interaction model of the device. I think it is only looking for Screen Readers.

Share:
927
Crush Lover
Author by

Crush Lover

Updated on December 08, 2022

Comments

  • Crush Lover
    Crush Lover over 1 year

    We are in are requirement of handling different level of user experience for the user who are using screen readers.

    We need to implement some logic only if the screen reader is enabled.

    if(isScreenReaderOn){
        logic A goes here
    } else {
        logic B goes here
    }
    

    But I was not able to find out a way in Flutter to check whether the screen reader of the device is on.

    I went through the following links but I was not able to find out a clear solution.

    They seem use it internally but I can't realize it clearly to apply in my case.

    Really appreciate if you can support on this.

  • Tsundoku
    Tsundoku over 5 years
    Nice. Does that media query only detect screen readers (TalkBalk, VoiceOver) or also other types of assistive technologies, such as magnification?
  • Crush Lover
    Crush Lover over 5 years
    I tested the code with enabling magnification and select-to-speak features.. but no change happened of the output. As It originated from accessibleNavigation property of [Window.AccessibilityFeatures],. It results whether there is a running accessibility service which is changing the interaction model of the device. I think it is only looking for Screen Readers.
  • Tsundoku
    Tsundoku over 5 years
    It would be good to add that to your answer. Comments might disappear at some points.