1

In my flutter app i want to increase the font weight while enabled Bold Text in android Accessibility setting. I have used MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: true) . But font text is not chaning. How to fix this issue? How to enable bold text when system font is bold?

When i am using useInheritedMediaQuery: true Then the text became bold. But when i disabled bold text in android accessibility. Then also the text is bold.

My requirement is when "bold text" enabled then the text want to be bold. If it is disabled then the text wants to non bold .

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MediaQuery(
        data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: true),
        child:MaterialApp(
          title: 'Flutter Demo',
          useInheritedMediaQuery: true,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        ));
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Text Wants to be bold',
              style: TextStyle(fontSize: 40),
            ),

          ],
        ),
      ),
    );
  }
}

Android accessibility settings

flutter app

Joe
  • 959
  • 2
  • 11
  • 27

1 Answers1

0

you can try this solution MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: true),

return MediaQuery(
  data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: true),
  child: MaterialApp(
    useInheritedMediaQuery: true,
  ),
);

via this answer: https://stackoverflow.com/a/70061828/16402513

  • It will be always bold. If i disable the bold text in android sccessibility. The text will be bold but i want to be not bold. – Joe Nov 01 '22 at 14:20
  • I added the source code can u check again. – Joe Nov 02 '22 at 02:32