废话不多说先上代码:
double hc_ScreenWidth() {
return window.physicalSize.width/window.devicePixelRatio;
}
double hc_ScreenHeight(){
return window.physicalSize.height/window.devicePixelRatio;
}
double hc_FitWidth(double width) {
return hc_ScreenWidth()/375.0 *width;
}
double hc_FitHeight(double height) {
return hc_ScreenHeight()/667.0 *height;
}
包含头文件:import 'dart:ui';
window.physicalSize.width获取到的是屏幕宽的像素px,所以用window.physicalSize.width/window.devicePixelRatio转化成开发中使用的point 即pt。后面的同理获得。