Home > database >  (Flutter) How do I prevent Android device Display size scaling in my app?
(Flutter) How do I prevent Android device Display size scaling in my app?

Time:02-06

(Flutter) How do I prevent Android device Display size scaling in my app?

I use MediaQuery to lock the font size.

builder: (context, child) {
  return MediaQuery(
    child: child!,
    data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
  );
},

pic

However, there is a setting called "Display Size" in the Android phone.

This setting scales my flutter App and make the content out of bound.

How do I prevent it?

CodePudding user response:

There is an open issue in Flutter, regarding modifying the logical pixel size, which is related to the problem you're having: https://github.com/flutter/flutter/issues/32115

  • Do note, There is a property in the MediaQuery called devicePixelRatio which updates when "Display size" changes in the settings.

  • Unfortunately, devicePixelRatio does not affect the sizing of the widgets, the size of widgets would change - even if you provide a custom fixed value.

I would suggest you to:

  • Either see if any workarounds or packages suggested in the issue above is suitable for your problem.
  • Or maybe preferably, update the content of your app to be more responsive to different accessibility settings like text size or display size.

CodePudding user response:

The MediaQuery can lock the option for size inside your application but not for the Mobile Phone Display Scaling option. For further responsiveness you can use multiple other options like

  • Layout Builder
  • Fitted Box (To wrap Text widget)
  •  Tags:  
  • Related