![](/img/trans.png)
[英]Locked landscape orientation on tablet + activity started when device in portrait = visible rotation on screen
[英]Enable Device Screen Rotation Landscape or Potrait, only for Tablet Device by Flutter
我想让我的应用程序屏幕仅适用于平板电脑横向或纵向。 Still on Portrait for smart 应用程序由 Flutter 开发。
检查设备是平板电脑
class DeviceUtil {
static String get _getDeviceType {
final data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);
return data.size.shortestSide < 550 ? 'phone' : 'tablet';
}
static bool get isTablet {
return _getDeviceType == 'tablet';
}
}
DeviceUtil.isTablet; //true
使用这个
if(DeviceUtil.isTablet){
//landscape-or-potrait
}else{
//landscape-or-potrait
}
您可以使用SystemChrome设置肖像
final data = MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
if(data.size.shortestSide > 600) { // check if its bigger
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
} else { // otherwise will be ..
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
}
玩数字以获得最好的
你可以试试...
final data = MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
if(data.size.shortestSide < 600) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.