重现步骤
- 运行示例代码
- 根据
PreferredOrientations
将设备旋转至横向模式
预期结果
设备应根据 List 中选择的 PreferredOrientations
进行旋转。
实际结果
- 如果你设置:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeRight
]);
或者:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft
]);
设备在 portraitUp
时完全不旋转。
- 如果你设置:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft
]);
设备在所有三个方向上完美旋转。
代码示例
代码示例
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeRight
]);
runApp(const TestWidget());
}
class TestWidget extends StatefulWidget {
const TestWidget({super.key});
@override
State<TestWidget> createState() => _TestWidgetState();
}
class _TestWidgetState extends State<TestWidget> {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text("Hello world !"),
),
),
);
}
}
截图或视频
截图/视频演示
[上传媒体在这里]
日志
日志
[Paste your logs here]
Flutter Doctor 输出
Doctor 输出
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-x64, locale fr-FR)
• Flutter version 3.19.6 on channel stable at /Users/foxtom/Desktop/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 54e66469a9 (10 days ago), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/foxtom/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.88.1)
• VS Code at /Users/foxtom/Desktop/Visual Studio Code.app/Contents
• Flutter extension version 3.46.0
[✓] Connected device (5 available)
• moto g 8 power (mobile) • ZY22BNDW2C • android-arm64 • Android 11 (API 30)
• iPhone de Nathalie (mobile) • 00008030-000E64110A8A802E • ios • iOS 17.4.1 21E236
• Now You See Me (mobile) • 00008020-001204401E78002E • ios • iOS 17.4.1 21E236
• macOS (desktop) • macos • darwin-x64 • macOS 14.4.1 23E224 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.92
! Error: Browsing on the local area network for Apple Watch de Tom. Ensure the device is unlocked and discoverable via Bluetooth. (code -27)
[✓] Network resources
• All expected network resources are available.
• No issues found!
4条答案
按热度按时间piwo6bdm1#
Thanks for the report @Tom3652
Is this specific to iOS or Android ?
Also, please check below issues and see if they help in your case or not.
#34230
#73651
piv4azn72#
自从你给我展示过旧的问题,我已经测试了它们,我也使用最新的flutter版本
3.19.6
测试了所有内容。以下测试是在问题中的我的示例代码中进行的。
portraitDown
出现错误Failed to change device orientation: Error Domain=UISceneErrorDomain Code=101 "None of the requested orientations are supported by the view controller. Requested: portraitUpsideDown; Supported: landscapeRight" UserInfo={NSLocalizedDescription=None of the requested orientations are supported by the view controller. Requested: portraitUpsideDown; Supported: landscapeRight}
外,每个旋转(或旋转组合)都正常工作。注意:如果你直接在Xcode中取消选中旋转(在这种情况下,
SystemChrome
无法执行任何操作),则旋转会被阻止。portraitUp
&&landscapeRight
或portraitUp
&&landscapeLeft
,只有portraitUp
可以正常工作。portraitUp
&&landscapeRight
&&landscapeLeft
,它可以正常工作。landscapeRight
||landscapeLeft
,它会以正确的方向开始,但不会旋转到其他方向。这是我最初的问题评论。
目前我已经完成了所有的测试,我还没有尝试在Android上使用
portraitDown
,但当然,我会在完成后更新评论。myss37ts3#
请注意团队-iOS:我已经在处理一个与Android方向变化相关的问题 - #144307。因此,我可以调查这部分与Android相关的代码。然而,似乎存在一个跨平台问题与
SystemChrome.setPreferredOrientations
有关。如上所述,过去还报告了几个其他iOS问题。针对#147460(评论),我们可能需要澄清关于Xcode的预期iOS行为。tzdcorbm4#
这个问题的解决方案需要进一步讨论(参见#148136)。
因此,我现在将自己取消分配。