我在 Flutter 上创建了一个新应用程序,但在不同设备之间切换时出现了屏幕尺寸问题。
我使用 Pixel 2XL 屏幕尺寸创建了应用程序,并且因为我有一个带有 ListView
子级的容器,它要求我包含容器的高度和宽度。
所以当我将设备切换到新设备时,容器太长并引发错误。
如何才能使应用程序针对所有屏幕进行优化?
最佳答案
你可以使用:
双宽度 = MediaQuery.of(context).size.width;
双倍高度 = MediaQuery.of(context).size.height;
要获得 SafeArea 的高度(适用于 iOS 11 及更高版本):
var padding = MediaQuery.of(context).padding;
double newheight = height - padding.top - padding.bottom;
https://stackoverflow.com/questions/49553402/