I would like to enable my application screen to landscape or portrait only for tablets. Still on Portrait for smartphone The application was developed by Flutter.
CodePudding user response:
check device is tablet
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
use of this
if(DeviceUtil.isTablet){
//landscape-or-potrait
}else{
//landscape-or-potrait
}
CodePudding user response:
You can set portrait with 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,
]);
}
Play with digit to get the best
CodePudding user response:
You can try...
final data = MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
if(data.size.shortestSide < 600) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}