您可以使用flutter_device_type包中的以下代码片段:
import 'dart:ui' as ui;
bool isTablet;
bool isPhone;
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size size = ui.window.physicalSize;
final double width = size.width;
final double height = size.height;
if(devicePixelRatio < 2 && (width >= 1000 || height >= 1000)) {
isTablet = true;
isPhone = false;
}
else if(devicePixelRatio == 2 && (width >= 1920 || height >= 1920)) {
isTablet = true;
isPhone = false;
}
else {
isTablet = false;
isPhone = true;
}
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用device_info包获取更全面的信息。
| 归档时间: |
|
| 查看次数: |
3242 次 |
| 最近记录: |