วิธีทำให้ App Flutter รองรับแค่แนวตั้งหรือแนวนอนเท่านั้น
1 min readMay 26, 2020
มาแนะนำเคล็ดลับเล็กๆน้อยๆครับ
Portrait mode
เริ่มจาก Import package:flutter/services.dart
หลังจากนั้นก็ใส่
void main() async {
///
/// Force the layout to Portrait mode
///
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]).then((_){
runApp(...);
});
}
Landscape mode
void main() async {
///
/// Force the layout to Portrait mode
///
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight
]).then((_){
runApp(...);
});
}
แต่วิธีนี้ IOS บางเครื่องจะไม่ได้ผล ทาง flutter ก็แนะนำว่าให้ไปตั้งค่า UISupportedInterfaceOrientations ที่ Info.plist ครับ
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>