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.71k stars 27.62k forks source link

Flutter fragment.onPostResume() causes the app bar to hide under status bar #87623

Open Kabilan21 opened 3 years ago

Kabilan21 commented 3 years ago

hi,

I am using Flutter add-to-app implementation. I have a MainActivity that extends AppCompatActivity . it has two fragments, a native fragment, and a Flutter fragment. App theme is currently set to noActionBar. I have a custom app bar in the layout_main.xml

adding flutterFragment.onPostResume() causes the app bar to partially hide under the status bar.

A single line change removing flutterFragment.onPostResume() makes the app work as expected .

TahaTesser commented 3 years ago

Hi @Kabilan21 Can you please provide your flutter doctor -v & a minimal complete reproducible code sample in a repository Thank you

Kabilan21 commented 3 years ago

Hi @TahaTesser

You can find the app here .In MainActivity you can find onPostResume() . Initially, flutter fragment is loaded, it contains a button to navigate to the native fragment .

I placed the appbar inside fragment.xml , the issue is same if the appbar is placed inside the activity_main.xml layout.

By clicking "Navigate to native" button you can navigate to native fragment . It has a App bar but it is hidden in presence of the code flutter.onPostResume();

Without the presence of the flutterfragment.onPostResume() ,sometimes if the app is opened and in the memory for a long time, and the app is opened again, it crashes. I am not sure the crash is due to not handling of flutterfragment.onPostResume().

Run flutter pub get in flutter module directory to generate the necessary files for flutter module.

TahaTesser commented 3 years ago

Hi @Kabilan21 Thanks for the code sample, I can reproduce the issue

https://user-images.githubusercontent.com/48603081/128337129-bcd44c22-5ab6-4c8f-a172-01f8da70cd62.mp4

stable master

Check flutter doctor -v outputs for each channel below

flutter doctor -v ```console [✓] Flutter (Channel stable, 2.2.3, on macOS 12.0 21A5294g darwin-x64, locale en-GB) • Flutter version 2.2.3 at /Users/tahatesser/Code/flutter_stable • Framework revision f4abaa0735 (5 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/tahatesser/Code/SDK • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = /Users/tahatesser/Code/SDK • Java binary at: /Users/tahatesser/Code/openjdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode-beta.app/Contents/Developer • Xcode 13.0, Build version 13A5201i • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (version 2020.3) • 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 ✗ Unable to find bundled Java version. • Try updating or re-installing Android Studio. [✓] VS Code (version 1.58.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.25.0 [✓] Connected device (3 available) • Redmi K20 Pro (mobile) • def0ad20 • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 12.0 21A5294g darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.131 ! Doctor found issues in 1 category. ``` ```console [✓] Flutter (Channel master, 2.5.0-2.0.pre.181, on macOS 12.0 21A5294g darwin-x64, locale en-GB) • Flutter version 2.5.0-2.0.pre.181 at /Users/tahatesser/Code/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision e40d7e6ef4 (4 hours ago), 2021-08-05 14:15:04 +0800 • Engine revision c3739afe0a • Dart version 2.14.0 (build 2.14.0-377.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/tahatesser/Code/SDK • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = /Users/tahatesser/Code/SDK • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode-beta.app/Contents/Developer • Xcode 13.0, Build version 13A5201i • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2020.3) • 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 11.0.10+0-b96-7281165) [✓] VS Code (version 1.58.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.25.0 [✓] Connected device (3 available) • Redmi K20 Pro (mobile) • def0ad20 • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 12.0 21A5294g darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.131 • No issues found! ```

✅: No Issue ❌: Issue reproduced

chinmaygarde commented 3 years ago

cc @blasten

Rempage commented 3 years ago

嗨@Kabilan21 感谢您提供代码示例,我可以重现该问题

Screenrecorder-2021-08-05-13-36-45-881.mp4 stable master ❌ ❌ 检查flutter doctor -v下面每个通道的输出

颤振医生 -v ✅: 没有任何问题 ❌: 问题转载

I also encountered the same problem in the project. If this method is not called, the problem will not occur when the app enters the foreground.

How can I solve this problem? If I don't call onpostresume, will it cause other problems?

Rempage commented 3 years ago

hi,

I am using Flutter add-to-app implementation. I have a MainActivity that extends AppCompatActivity . it has two fragments, a native fragment, and a Flutter fragment. App theme is currently set to noActionBar. I have a custom app bar in the layout_main.xml

adding flutterFragment.onPostResume() causes the app bar to partially hide under the status bar.

A single line change removing flutterFragment.onPostResume() makes the app work as expected .

I have found a solution, which can be solved by overriding the onpostresume method and calling setsystemuivisibility again

Kabilan21 commented 3 years ago

hi @Rempage,

can you share the solution in code? specifically the onPostResume() override.

Rempage commented 3 years ago

hi @Rempage,

can you share the solution in code? specifically the onPostResume() override.

@Override
protected void onPostResume() {
    super.onPostResume();
    if (mainFrag != null) {
        mainFrag.onPostResume();
    }
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}

You can try it. You can set other enumeration parameters.