Flutter アプリに横縦制限をかける
アプリの開発中、要件上、アプリの横表示、縦表示に制限をかけたいことがよくあります。
Androidの場合は AndroidManifest.xml のactivityのscreenOrientation属性を設定することで実現可能です。
<activity
…
android: screenOrientation=”portrait”
</activity>
iOSの場合Info.plistのUISupportedInterfaceOrientationのUIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight属性で設定可能です。
<key>UISupportedInterfaceOrientation</key>
<array>
…
<string>UIInterfaceOrientationPortrait</string>
</array>
Flutterでは以下の方法で実現可能です。
void main() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]).then((_){
runApp(MyApp());
})
}