flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.19k stars 27.49k forks source link

DeviceOrientation.portraitDown doesn't work. #40745

Closed dumplings closed 4 years ago

dumplings commented 5 years ago

code show

I used the following code to write an app. The app has 4 buttons that both trigger SystemChrome.setPreferredOrientations. The difference is in different directions. My question is: Why is the result of portraitDown and portraitUp the same, is it the way I use it? wrong?

class Body extends StatelessWidget {
  _changeOrientation(DeviceOrientation orientation) {
    return () => SystemChrome.setPreferredOrientations([orientation]);
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: <Widget>[
        RaisedButton(
          child: Text('portraitUp'),
          onPressed: _changeOrientation(DeviceOrientation.portraitUp),
        ),
        RaisedButton(
          child: Text('landscapeLeft'),
          onPressed: _changeOrientation(DeviceOrientation.landscapeLeft),
        ),
        RaisedButton(
          child: Text('portraitDown'),
          onPressed: _changeOrientation(DeviceOrientation.portraitDown),
        ),
        RaisedButton(
          child: Text('landscapeRight'),
          onPressed: _changeOrientation(DeviceOrientation.landscapeRight),
        ),
      ],
    );
  }
}

Logs

flutter doctor -v
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale zh-Hans-CN)
    • Flutter version 1.7.8+hotfix.4 at /Users/hejingguo/flutter
    • Framework revision 20e59316b8 (9 weeks ago), 2019-07-18 20:04:33 -0700
    • Engine revision fee001c93f
    • Dart version 2.4.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/hejingguo/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/hejingguo/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.3, Build version 10G8
    • CocoaPods version 1.7.3

[✓] iOS tools - develop for iOS devices
    • ios-deploy 1.9.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 36.1.4
    • Dart plugin version 191.7830

[✓] VS Code (version 1.37.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.3.0

[✓] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!
escamoteur commented 5 years ago

Do you mean you are not able to run the App upside-down? Or what do you mean its the same?

Do you see this behavior on iOS and Android? Maybe this problem? https://stackoverflow.com/questions/50456573/flutter-allow-iphone-upside-down

dumplings commented 5 years ago

Do you mean you are not able to run the App upside-down? Or what do you mean its the same?

Do you see this behavior on iOS and Android? Maybe this problem? https://stackoverflow.com/questions/50456573/flutter-allow-iphone-upside-down

this behavior on android, and not the stackoverflow's problem.

The official document says "The orientation that is 180 degrees from portraitUp." but my what i really got is the portraitDown's behavior is same like portraitUp, not 180 degrees from portraitUp, still same, like this:

1568807320331383

escamoteur commented 5 years ago

You could give this package a try https://pub.dartlang.org/packages/auto_orientation

There is also this known bug https://github.com/flutter/flutter/issues/13238

slightfoot commented 5 years ago

@dumplings At a guess if you edit your android\app\src\main\AndroidManifest.xml and modify the <activity> tag that has android:name=".MainActivity" attribute. Add android:screenOrientation="fullSensor". This should then allow it to go into reverse portrait.

dumplings commented 5 years ago

@dumplings At a guess if you edit your android\app\src\main\AndroidManifest.xml and modify the <activity> tag that has android:name=".MainActivity" attribute. Add android:screenOrientation="fullSensor". This should then allow it to go into reverse portrait.

I have tried your suggestion, still not work.

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="flutter_one"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:screenOrientation="fullSensor"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
TahaTesser commented 4 years ago

Issue does exist on

Flutter 1.12.13+hotfix.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 0b8abb4724 (4 weeks ago) • 2020-02-11 11:44:36 -0800
Engine • revision e1e6ced81d
Tools • Dart 2.7.0
Code Sample ``` import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Material App', theme: ThemeData.dark(), home: Home(), ); } } class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Material App Bar'), ), body: Body(), floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () {}, ), ); } } class Body extends StatelessWidget { _changeOrientation(DeviceOrientation orientation) { return () => SystemChrome.setPreferredOrientations([orientation]); } Widget build(BuildContext context) { return Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ RaisedButton( child: Text('portraitUp'), onPressed: _changeOrientation(DeviceOrientation.portraitUp), ), RaisedButton( child: Text('landscapeLeft'), onPressed: _changeOrientation(DeviceOrientation.landscapeLeft), ), RaisedButton( child: Text('portraitDown'), onPressed: _changeOrientation(DeviceOrientation.portraitDown), ), RaisedButton( child: Text('landscapeRight'), onPressed: _changeOrientation(DeviceOrientation.landscapeRight), ), ], ); } } ```
Logs ``` ```
pedromassangocode commented 4 years ago

Hi @dumplings I cannot reproduce the issue on latest master channel. rotation

Closing this a probably fixed. If you disagree please comment and I will reopen it. Thank you

flutter doctor -v ``` [✓] Flutter (Channel master, 1.21.0-10.0.pre.212, on Mac OS X 10.15.6 19G2021, locale en) • Flutter version 1.21.0-10.0.pre.212 at /Users/pedromassango/dev/SDKs/flutter_master • Framework revision eef4220a87 (13 hours ago), 2020-08-20 17:46:07 -0700 • Engine revision 4dc866283d • Dart version 2.10.0 (build 2.10.0-45.0.dev) [!] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at /Users/pedromassango/Library/Android/sdk • Platform android-30, build-tools 30.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [✓] Xcode - develop for iOS and macOS (Xcode 11.6) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.6, Build version 11E708 • CocoaPods version 1.9.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] IntelliJ IDEA Community Edition (version 2020.2) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 48.1.4 • Dart plugin version 202.6397.47 [!] VS Code (version 1.48.0) • VS Code at /Applications/Visual Studio Code.app/Contents ✗ Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [✓] Connected device (3 available) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G2021 • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 84.0.4147.135 ! Doctor found issues in 3 categories. ```
github-actions[bot] commented 3 years ago

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 flutter doctor -v and a minimal reproduction of the issue.