Skip to content
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

Navigator.push freezes the app on receipt of platform msg before AppLifeCycleState.resumed #13818

Closed
FastNinja opened this issue Jan 1, 2018 · 19 comments · Fixed by #16261
Closed
Assignees
Labels
c: regression It was better in the past than it is now f: routes Navigator, Router, and related APIs.

Comments

@FastNinja
Copy link

FastNinja commented Jan 1, 2018

Steps to Reproduce

  1. Attach a function to the button onTap
  2. Invoke an ImagePicker to select an image from the gallery (image_picker package)
  3. Initiate Navigator.push to a new screen after image is picked.
  4. application is frozen. navigation did not happen.

Observations:

  • Removing Image Picker from equation solves the problem.
  • Tested in iOS simulator and real device - similar behavior
  • the issue appeared after recent flutter update i.e. it woeked on 4 weeks old flutter (dev branch)).

This is the code that hangs (full sample app can be found here https://github.com/FastNinja/imagepickerissue
):

Future<Null> _freezesAfterNavigation(BuildContext context) async {
    var _imageFile = await ImagePicker.pickImage();

    // this navigation freezes and the whole app
    Navigator
        .of(context, rootNavigator: true)
        .push(new MaterialPageRoute<String>(
            settings: const RouteSettings(name: '/screen2'),
            builder: (BuildContext context) {
              return new Screen2Page();
            }));
  }

//... somewhere in the app...

     new RaisedButton(
              child: new Text("Select Image and Freezes"),
              onPressed: () => _freezesAfterNavigation(context),
            ),

I have created the following repository to easily reproduce the issue.
https://github.com/FastNinja/imagepickerissue

image

It is the Minimum Possible App that reproduces the issue - single page with 2 buttons.
1st button just navigates to new screen. 2nd button picks an image and then navigates to new screen.
Using the image picker does not initiate navigation into new screen and the whole application gots frozen.

Logs

Run your application with flutter run and attach all the log output:

Launching lib/main.dart on iPhone 6 in debug mode...
Running pod install...                                1.1s
Running Xcode build...                               12.2s
Syncing files to device iPhone 6...                   0.9s

🔥  To hot reload your app on the fly, press "r". To restart the app entirely, press "R".
An Observatory debugger and profiler on iPhone 6 is available at: http://127.0.0.1:8105/
For a more detailed help message, press "h". To quit, press "q".
PlatformException(multiple_request, Cancelled by a second request, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:514:7)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:154:18)
<asynchronous suspension>
#2      ImagePicker.pickImage (package:image_picker/image_picker.dart:63:40)
<asynchronous suspension>
#3      _MyHomePageState._freezesAfterNavigation (/Users/user/Documents/sandpit/imagepickerissue/lib/main.dart:41:40)
<asynchronous suspension>
#4      _MyHomePageState.build.<anonymous closure> (/Users/user/Documents/sandpit/imagepickerissue/lib/main.dart:78:32)
#5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:323:14)
#6      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:375:30)
#7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102<…>

Run flutter analyze and attach any output of that command also:

flutter analyze
Analyzing /imagepickerissue...
  hint • The value of the local variable '_imageFile' isn't used at lib/main.dart:41:9 • unused_local_variable
1 issue found.
(Ran in 5.0s)

Flutter Doctor

flutter doctor

[✓] Flutter (on Mac OS X 10.12.6 16G1114, locale en-US, channel alpha)
    • Flutter at /Users/user/Documents/flutter
    • Framework revision 8f65fec5f5 (3 weeks ago), 2017-12-12 09:50:14 -0800
    • Engine revision edaecdc8b8
    • Tools Dart version 1.25.0-dev.11.0
    • Engine Dart version 2.0.0-edge.d8ae797298c3a6cf8dc9f4558707bd2672224d3e

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.1)
    • Android SDK at /Users/userhere/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.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_152-release-915-b08)

[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.2, Build version 9C40b
    • ios-deploy 1.9.2
    • CocoaPods version 1.3.1

[✓] Android Studio (version 3.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)

[✓] Connected devices
    • iPhone 6 • 2F890940-D8CE-40A0-B937-A93115097CDE • ios • iOS 11.2 (simulator)

For more information about diagnosing and reporting Flutter bugs, please see https://flutter.io/bug-reports/.

@oliverchang
Copy link

oliverchang commented Jan 2, 2018

I am running into a very similar issue on Android (triggering FB SDK login flow instead of image picker). manually downgrading to 0.19 seems to resolve this, while master still seems broken.

@Hixie
Copy link
Contributor

Hixie commented Jan 2, 2018

cc @mravn-google

@Hixie Hixie added plugin: first party c: regression It was better in the past than it is now labels Jan 2, 2018
@Hixie Hixie added this to the 3: Current Milestone milestone Jan 2, 2018
@Hixie
Copy link
Contributor

Hixie commented Jan 2, 2018

Marking m3 since this sounds like a regression.

@FastNinja
Copy link
Author

@Hixie thanks for prioritizing it. any suggested workaround? hacks? anything I can do to make it work?

@FastNinja
Copy link
Author

@oliverchang how do you manually downgrade to 0.19?

@mravn-google mravn-google self-assigned this Jan 3, 2018
@oliverchang
Copy link

@FastNinja I just did a git checkout to the 0.19 revision (fd7853f) in my flutter checkout.

@mravn-google
Copy link
Contributor

@Hixie This may not actually be an ImagePicker problem, since it is reported to work fine with version 0.0.19 of Flutter, and a similar issue has been reported with navigation following other platform interactions (#13818 (comment)).

@FastNinja Until we fix this, it seems that delaying the Navigator.push after the platform view is dismissed is a workaround:

var imageFile = await ImagePicker.pickImage();
await new Future.delayed(new Duration(milliseconds: 100));
Navigator.of(...).push(...)

Wondering if the problem is bad interaction between navigation and the app lifecycle handling that takes place when the platform view (e.g. for ImagePicker, the image gallery) is dismissed and the FlutterView returns to the foreground.

@BenSower
Copy link

BenSower commented Jan 5, 2018

I am not quite sure, but I think I ran into a similar issue both using the external barcodescanner- and location-plugins. Both seemed to disappear when downgrading to 0.0.19 as well as using @mravn-google 's delay method. The only difference with my problem is that the alert dialog I was trying to display (which is also being pushed after a platform call, hence this comment), seems to be being displayed, yet it is invisible. I noticed this, since I it seemed to "catch" all my taps that were hitting the invisible alertDialog, but once I tapped outside of the invisible alertDialog, it was dismissed properly and I could continue using my app as intended.

mintware-de/flutter_barcode_reader#3

P.S.: I think I'll start writing a Sherlock Holmes-style book called "Ben Sower and the invisible alertDialog".

@mravn-google mravn-google removed their assignment Jan 5, 2018
@mravn-google
Copy link
Contributor

Regression seems to have been introduced by #13344 (@FastNinja's example works fine just before that commit, and not after).

Steps to reproduce on Android:

  1. Invoke some plugin (or Java code) that pushes a new activity on top of the Flutter app and then sends a platform message to the Flutter app from the onActivityResult handler.
  2. Have the message receiver on the Dart side invoke Navigator.push.

It appears we have a problem when step 2 above executes before AppLifeCycleState is back at resumed. If we postpone the Navigator.push call until we've received both the platform message and a WidgetsBindingObserver.didChangeAppLifecycleState with AppLifeCycleState.resumed, the example works fine.

/cc @Hixie

@mravn-google mravn-google changed the title Navigator.push freezes the app after Image Picker is used Navigator.push freezes the app on receipt of platform msg before AppLifeCycleState.resumed Jan 6, 2018
@lschmierer
Copy link

Same issue was reported here #13600

@mit-mit
Copy link
Member

mit-mit commented Jan 10, 2018

cc @Hixie, another developer reported this on gitter today

@Hixie
Copy link
Contributor

Hixie commented Apr 3, 2018

cc @jonahwilliams Does your patch for split-screen solve this too?

@jonahwilliams
Copy link
Member

jonahwilliams commented Apr 3, 2018

If the original issue is referring to iOS behavior, no. However, I bet the root cause is similar, so I can start looking at it. The android instances I can verify. If it doesn't fix them, it may just make them less frequent.

@jonahwilliams
Copy link
Member

I can reproduce the iOS issue. It looks like frames are being scheduled correctly after returning from the image picker, however the animation to bring the route into view doesn't function correctly. Possibly it starts too soon? The overlay is blocking touch events too I believe, making it appear as though the app has frozen. However if you place a animating widget on the home page, you'll still see it animating correctly.

@Hixie
Copy link
Contributor

Hixie commented Apr 4, 2018

Very weird.

@jonahwilliams
Copy link
Member

Did some ticker debugging after speaking with @yjbanov offline. It looks like we are creating the route transition ticker before resuming animating. As a result, it is getting canceled - and all of the animations that depend on it aren't firing.

---- Open Image Picker Here ---
flutter: framesEnabled: false
flutter: AppLifecycleState.paused
---- Close Image Picker Here ---
flutter: created controller!
flutter: Ticker#240207997 created
flutter: Ticker#240207997 stopped. canceled: true
flutter: Ticker#240207997 started
viewWillAppear
flutter: framesEnabled: true
flutter: AppLifecycleState.inactive
flutter: Ticker#9974983 created
flutter: Ticker#87268972 created
flutter: Ticker#883598275 created
flutter: Ticker#440164322 created
flutter: Ticker#860434551 created
flutter: Ticker#928659338 created
flutter: Ticker#148737668 created
flutter: Ticker#437074620 created
viewDidAppear
flutter: framesEnabled: true
flutter: AppLifecycleState.resumed

@Hixie
Copy link
Contributor

Hixie commented Apr 4, 2018

How is it getting canceled?

@jonahwilliams
Copy link
Member

Actually - it looks like canceling is in the animation controller and expected. However, after that it tries to start() the animation. This checks, among other things, the current schedulerPhase and refuses to start animating if it is SchedulerPhase.idle (which it is).

The ticker never gets resumed, I'm not sure if it should.

@github-actions
Copy link

github-actions bot commented Sep 3, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: regression It was better in the past than it is now f: routes Navigator, Router, and related APIs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants