-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rotate issue on iOS only #116711
Comments
Hello @SwiftyFlow. Thank you for filing this issue. Can you please provide the following information?
Please provide the information in the form of text. See how to make collapsible sections with Markdown here. |
flutter doctor -v [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.1) [✓] VS Code (version 1.74.0) [✓] Connected device (2 available) [✓] HTTP Host Availability • No issues found! |
flutter run -v:Not allowed to give private company data. flutter run -v -> prints confidential data - cannot provide that... |
Please provide a code sample as mentioned in #116711 (comment) |
|
@SwiftyFlow The code you provided is long and complex. Please try to simplify the example you are providing to have the minimal code to reproduce this issue |
If I don't give the full logic how can we spot the error? |
Code Sampleimport 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((_) {
runApp(const MyApp());
});
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
appBarTheme: const AppBarTheme(systemOverlayStyle: SystemUiOverlayStyle.light),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
routes: {
SecondScreen.routeName: (ctx) => const SecondScreen(),
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.all(20),
child: Text(
'This screen should not rotate. Notice some kind of glitch when coming back from second screen in landscape. And also if coming back in portrait but then tries to rotate in landscape here.',
textAlign: TextAlign.center,
),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pushNamed(SecondScreen.routeName);
},
child: const Text('Go to second screen'),
)
],
),
));
}
}
class SecondScreen extends StatefulWidget {
static const routeName = '/second-screen';
const SecondScreen({Key? key}) : super(key: key);
@override
State<SecondScreen> createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: const Center(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text(
'Only this screen should be able to rotate but it only does the very first time it shows. Never after...\n\nOnly fix: fully restart the app.',
textAlign: TextAlign.center,
),
),
),
);
}
} |
Colours removed that's all I can do |
Triage reportI can reproduce this issue on Code Sample (Same as OP)import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((_) {
runApp(const MyApp());
});
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
appBarTheme: const AppBarTheme(systemOverlayStyle: SystemUiOverlayStyle.light),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
routes: {
SecondScreen.routeName: (ctx) => const SecondScreen(),
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.all(20),
child: Text(
'This screen should not rotate. Notice some kind of glitch when coming back from second screen in landscape. And also if coming back in portrait but then tries to rotate in landscape here.',
textAlign: TextAlign.center,
),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pushNamed(SecondScreen.routeName);
},
child: const Text('Go to second screen'),
)
],
),
));
}
}
class SecondScreen extends StatefulWidget {
static const routeName = '/second-screen';
const SecondScreen({Key? key}) : super(key: key);
@override
State<SecondScreen> createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: const Center(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text(
'Only this screen should be able to rotate but it only does the very first time it shows. Never after...\n\nOnly fix: fully restart the app.',
textAlign: TextAlign.center,
),
),
),
);
}
} |
Related to flutter/engine#36874 |
I don't really get what I need to do... |
@SwiftyFlow thank you for the detailed report, you made it easy to track down! The fix has merged at flutter/engine#38230, and you can follow the instructions at https://github.com/flutter/flutter/wiki/Where's-my-Commit%3F#finding-the-framework-commit-that-contains-engine-commit-x to monitor when it will be available in Flutter. If you validate the fix, let us know here, otherwise there's nothing more for you to do. 🙂 |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
I have an app that is by design always limited to
DeviceOrientation.portraitUp
. We don't allow any other orientations except for one screen, which is used as PDF or Image viewer, I want to allow ONLY this view to rotate freely. It works fine on Android but not on iOS.I have added this in initState:
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]);
in that case, all good on Android, but no effect on iOS it's like it has only
DeviceOrientation.portraitUp
if I do:
That allows landscape rotations but I cannot do portrait...
Any ideas?
Not mentioned but I do do:
The text was updated successfully, but these errors were encountered: