您可以使用下面的代码让您的手机屏幕响应:
double getHeight(double screenHeightofthedeviceYouAreDebuging,BuildContextcontext,double size)
{
return (MediaQuery.of(context).size.height / screenHeight) * size;
}
因此,如果您使用 5 in screen 进行调试,则屏幕高度将为 640 或 MediaQuery.of(context).size。 (宽度和高度)将为您提供测试设备的屏幕尺寸
screen Height of the device You Are Debuging = 640
context = BuildContext
size = size you want to be as you image , container etc height 。
所以它会根据使用的设备转换屏幕的大小
double getWidth(double screenWidthofthedeviceYouAreDebuging,BuildContext context,double size){
return (MediaQuery.of(context).size.width / screenHeight) * size;
}
EdgeInsets padding(top,bottom,left,right,context){
return EdgeInsets.only(
top: getHeight(640, context, top),
bottom: getHeight(640, context, bottom),
left: getHeight(640, context, left),
right: getHeight(640, context, right));
}