The goal is not restrict whole iOS application orientation, but fix it as portrait when new ViewController presents.
Flutter has example how to start Flutter screen inside existing iOS app
func openFlutterApp() {
guard
let windowScene = UIApplication.shared.connectedScenes
.first(where: { $0.activationState == .foregroundActive && $0 is UIWindowScene }) as? UIWindowScene,
let window = windowScene.windows.first(where: \.isKeyWindow),
let rootViewController = window.rootViewController
else { return }
let flutterViewController = FlutterViewController(
project: nil,
nibName: nil,
bundle: nil)
flutterViewController.modalPresentationStyle = .overCurrentContext
flutterViewController.isViewOpaque = false
rootViewController.present(flutterViewController, animated: true)
}
}
I see that FlutterViewController has supportedInterfaceOrientations, but I don't have enough Swift knowledge to override it for portrait mode only. And will it became rotatable again after returning from Flutter screen?
P.S. For the default flutter app it is easy to lock orientation via SystemChrome.setPreferredOrientations(), but in a flutter module it is totally ignored and only the native hosting app orientation is applied. So the only way is to lock orientations globally or change them in ContentView.swift where Flutter screen starts.