I've tried to set a global textScaleFactor
along with the home
property in MaterialApp
but it is not possible, because it is asking for HomePageWidget()
separately. I am using GetMaterialApp()
in another project and I want this global textScaleFactor
there too, but there also I am using initialRoute
too. Is there any way to counter this situation other than specifying this property for every single Text()
widget?
Yes you can do this. In your GetMaterialApp you can use it inside "builder" attribute of GetMaterialApp.
And still you can use title,initialRoute,initialBinding and getPages, as I have mentioned in example below.
Example:
Widget build(BuildContext context) {
return GetMaterialApp(
builder: (BuildContext context, Widget? child) {
final MediaQueryData data = MediaQuery.of(context);
return MediaQuery(
data: data.copyWith(
textScaleFactor:
data.textScaleFactor > 1.2 ? 1.2 : data.textScaleFactor*1.05,
),
child: child!,
);
},
title: kAppName,
initialRoute: kSplashScreen,
initialBinding: ScreensBindings(),
getPages: RouteGenerator.getPages(),
debugShowCheckedModeBanner: false,
);
}