Search code examples
flutterflutter-layout

Flutter Application wide textScaleFactor and ScrollConfiguration


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?


Solution

  • 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.