Flutter Application wide textScaleFactor and ScrollConfiguration

Viewed 19

i would like to apply an application wide ScrollConfigurationand also textScaleFactorproperty.

I know, I can set the ScrollConfiguration this way:

@override
Widget build(BuildContext context) {
  return MaterialApp(

    home: const AuthGate(),
    builder: (context, child) {
      return ScrollConfiguration(
        behavior: MyBehavior(),
        child: child!,
      );
    },
  );
}

and set the textScaleFactor this way:

@override
Widget build(BuildContext context) {
  return MaterialApp(

  home: const AuthGate(),
  builder: (context, child) {
    
      final mediaQueryData = MediaQuery.of(context);

      return MediaQuery(
        data: mediaQueryData.copyWith(textScaleFactor: 1.0),
        child: child!,
      );
    },
  );
}

My question is, how can i apply both?

1 Answers

Try this:

@override
Widget build(BuildContext context) {
  return MaterialApp(

  home: const AuthGate(),
  builder: (context, child) {
    
      final mediaQueryData = MediaQuery.of(context);

      return MediaQuery(
        data: mediaQueryData.copyWith(textScaleFactor: 1.0),
        child: ScrollConfiguration(
           behavior: MyBehavior(),
           child: child!,
        ),
      );
    },
  );
}

But child property can be null, so pay attention about using null check there.

Related