วิธีทำให้ App Flutter รองรับแค่แนวตั้งหรือแนวนอนเท่านั้น

Patiphan Suwanich
1 min readMay 26, 2020

--

มาแนะนำเคล็ดลับเล็กๆน้อยๆครับ

https://www.kindpng.com/imgv/Twbxmo_please-rotate-your-device-to-landscape-mode-hd/

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>

--

--

Patiphan Suwanich
Patiphan Suwanich

Written by Patiphan Suwanich

Work at Major Development | Interest in Blockchain | looking for opportunities in my programmer’s life

No responses yet