Open timnew opened 3 years ago
I'm not 100% this is a flutter bug or there is something critical missed from the code.
As I'm actually expecting to get a callback from Flutter Engine when all the routes has been popped from the root Navigator
. So I can manually update the fragment stack.
I tried to use FlutterUiDisplayListener
to capture the callback from Flutter, but FlutterUiDisplayListener.onFlutterUiNoLongerDisplayed
was not called on all routes are popped, but called on FlutterActivity/FlutterFragment is closed.
Seems this is the similar issue as https://github.com/flutter/flutter/issues/67011 and https://github.com/flutter/flutter/issues/69879
Hi @timnew Can you please provide a minimal complete reproducible code sample in a repository to better address the issue Thank you
@TahaTesser Yes I can, here is the repo: https://github.com/timnew/flutter-issue-69956
Steps to reproduce:
Build and launch the Android app
Press the Launch Flutter Activity
button, flutter app will be launched
Pressed the Exit
button on flutter screen, to pop the main screen from navigator.
A funny screen show appear
Press physical back would return to Android Activity
Press Launch Flutter Activity
button again, a blank screen would shown
Same bug can be reproduced with FlutterFragment
too, but to make it simpler, I uses FlutterActivity
here
This issue can be somehow mitigated by checking whether current route is the last route in Navigator, if yes, calling SystemNavigator.pop
instead of calling Navigator.pop
.
But it still have issues:
SystemNavigator.pop
doesn't work for FlutterFragment
, which actually finishes the hosting activitypop
is different from the behaviour of pressing physical backSo far, it is not a completely unsolvable issue, but it would be relatively complicated issue to address, if considering Flutter side might have nested navigator, and flutter app doesn't know whether the flutter is hosted in a activity or fragment.
It would be nice to have:
SystemNavigator.pop()
if called rather than pop the last route from the navigator, when Navigator.pop
is invoked`SystemNavigator.pop
calls a delegate on FlutterFragment, which can be registered on FlutterFragment when it is created, which can finish the host activity by default it not get overriden.Maybe related to https://github.com/flutter/flutter/issues/67011
This issue is reproducible on the latest Flutter channels but the current result has been changed a little bit:
On Reproduction Steps
at https://github.com/flutter/flutter/issues/69956#issuecomment-723354500, it will show black screen instead of a funny screen as above. And then every time Launch Flutter Activity
again, the black screen still persists. There is no exception log from the console.
Update the labels for further investigation.
I'm adding a few new screens built with Flutter onto an exiting Android app with a pre-warmed engine. Everything works so smoothly until I tried to close the UI from the flutter side.
In stand-alone flutter app, when all routes popped from the root Navigator, the app is closed automatically. But in this app, the app popped into a funny screen.
This is the
home
or theMaterialApp
When I clicked
Exit
, it runsNavigator.pop(context);
I was expecting the
FlutterActivity
is finished, but it doesn't, and this is what I see on the screen: This is the same screen captured the by emulator screenshot tool, which is a blank screenI can leave this screen by press physical back, I can return to my native screen.
If I re-show the flutter screen again, I would see It renders a transparent view on it, but you can still see flutter debug ribbon.
If I triggers hot reload right now, I can see logs:
Steps to Reproduce
This is flutter side code
This is the android side code
Expected results:
When I pressed "Exit" button in flutter app, the last route is popped via
Navigator.pop
, the activity/fragment should be removed from the Android navigation stack, same as physical back button is pressed. I tried to hostFlutterFragment
in a activity or useFlutterActivity
directly, both has the renders the transparent view.Actual results: A transparent activity/fragment is still there, which can be dismissed by pressing physical back
Logs are attached below, expand it to see:
Logs
``` ``` ``` ⋊> flutter analyze Analyzing mobile-android... info • Unused import: 'package:flutter_module/screens/feedback/FeedbackDialog.dart' • flutter_module/lib/screens/app/FlutterApp.dart:5:8 • unused_import info • Unused import: 'package:flutter_module/screens/profile/ProfileScreen.dart' • flutter_module/lib/screens/app/FlutterApp.dart:6:8 • unused_import 2 issues found. (ran in 4.7s) ``` ``` [✓] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.5 19F101, locale en-AU) • Flutter version 1.22.2 at /Users/tim.wen/Workspace/flutter • Framework revision 84f3d28555 (3 weeks ago), 2020-10-15 16:26:19 -0700 • Engine revision b8752bbfff • Dart version 2.10.2 [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3) • Android SDK at /Users/tim.wen/Library/Android/sdk • Platform android-29, build-tools 29.0.3 • ANDROID_HOME = Users/tim.wen/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_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.1, Build version 12A7403 • CocoaPods version 1.9.3 [!] Android Studio • Android Studio at /Applications/Android Studio 4.2 Preview.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) [!] Android Studio (version 4.1) • 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) [✓] VS Code (version 1.50.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.16.0 [✓] Connected device (1 available) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator) ! Doctor found issues in 2 categories. ```