Flutter 根据不同屏幕尺寸的坐标放置标记(颤振)
所以我有一个标记小部件,可以用来放置图像。它将使用偏移设置x和y的坐标Flutter 根据不同屏幕尺寸的坐标放置标记(颤振),flutter,dart,coordinates,Flutter,Dart,Coordinates,所以我有一个标记小部件,可以用来放置图像。它将使用偏移设置x和y的坐标 Offset position = Offset(0.0, 0.0); 之后,如果我想放置小部件,它将是这样的 double baseWidth = window.physicalSize.width; double baseHeight = window.physicalSize.height; double newWidth = MediaQuery.of(context).size.width; double ne
Offset position = Offset(0.0, 0.0);
之后,如果我想放置小部件,它将是这样的
double baseWidth = window.physicalSize.width;
double baseHeight = window.physicalSize.height;
double newWidth = MediaQuery.of(context).size.width;
double newHeight = MediaQuery.of(context).size.height;
double newX = (newWidth*630)/baseWidth;
double newY = (newHeight*380)/baseHeight;
MarkerBox(
Offset(newX, newY,
'Box One',
Colors.blueAccent,
Image.asset("assets/marker_red.png",
height: 40, width: 40, fit: BoxFit.cover),
width / 4.5
),
但是,如果屏幕大小不同,标记的位置也会不同。无论屏幕大小如何,如何使其在一个位置保持静止?是因为坐标受不同屏幕大小的影响吗 您可以通过以下方式获得屏幕的宽度和高度:
double new_width=MediaQuery.of(context).size.width代码>
double new_height=MediaQuery.of(context).size.height代码>
new_x=(new_width*base_x)/base_width
new_y=(new_height*base_y)/base_height
double baseWidth=480代码>双基高度=960代码>诀窍是获得您想要在“基本”设备中的确切位置,并使用该值(基本分辨率和基本位置),将其他设备中的位置转换到您在基本设备上获得的相同位置