https://github.com/flutter/flutter/issues/27235#issuecomment-508995063
https://flutteragency.com/how-to-prevent-device-orientation-in-flutter/
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
...
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(new MyApp());
});
}
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
을 이용해서 고정
이것만으로 해결이 안되거나 에러가 발생하는 경우에는 다음 조치를 취해야 합니다.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<!-- <string>UIInterfaceOrientationLandscapeLeft</string> -->
<!-- <string>UIInterfaceOrientationLandscapeRight</string> -->
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<!-- <string>UIInterfaceOrientationPortraitUpsideDown</string> -->
<!-- <string>UIInterfaceOrientationLandscapeLeft</string> -->
<!-- <string>UIInterfaceOrientationLandscapeRight</string> -->
</array>
Info.plist 에서 Orientation 관련 속성 수정
<activity>
...
android:screenOrientation="portrait"
...
AndroidManifest.xml 에서 screenOrientation 수정
void main() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight])
.then((_) => runApp(MyApp()),
);
class SampleScreen extends StatefulWidget {
SampleScreen() : super();
@override
State<StatefulWidget> createState() => _SampleScreenState();
}
class _SampleScreenState extends State<SampleScreen>
with PortraitStatefulModeMixin<SampleScreen> {
@override
Widget build(BuildContext context) {
super.build(context);
return Text("Flutter - Block screen rotation example");
}
@override
void dispose() {
super.dispose();
}
}
PortraitStatefulModeMixin<SampleScreen> 을 사용한다.
super.build(context); 가 있다는 것을 주의