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