🍇
Flutterアプリを横向きに固定する方法(iPad対応)
Flutterで開発したアプリを横向きに固定したいときに以下のコードで行えます。
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight])
.then((_) => {runApp(MyApp())});
}
また、iPadでは個別に設定が必要で、開発しているFlutterアプリのディレクトリにあるiosフォルダのRunner.xcworkspaceを開きます。

左のウィンドウからRunnerをクリックし、Requires full screenにチェックをいれてiPadで確認してみましょう。

縦向きでもアプリが横向きになっていることが確認できました!

Discussion