flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

Crash On Android 11 Caused by java.lang.IllegalStateException Reply already submitted

Open liamsammut97 opened this issue 2 years ago • 1 comments

Getting a crash on android 11, i cant seem to replicate it but crashlytics log displaying this.

Caused by java.lang.IllegalStateException Reply already submitted io.flutter.embedding.engine.dart.DartMessenger$Reply.reply (DartMessenger.java:35) io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error (MethodChannel.java:14) com.lyokone.location.FlutterLocation.onActivityResult (FlutterLocation.java:48)

liamsammut97 avatar May 20 '22 11:05 liamsammut97

There is a problem with the package, specifically in the FlutterLocation.java class, where MethodChannel Result object is submitted back through dart binary messenger on several occurrences resulting in Reply already submitted error.

Use case execution scenario:

If user has location disabled, when application calls requestService method, and is presented with enable location service dialog, he then chooses to cancel the location service, the app crashes.

Code resulting in application crash:

In my case that happens, when i invoke requestPermission method before the getLocation method.


if (await location.requestPermission() == PermissionStatus.granted) {
      // get device location.
    return await location.getLocation()
  }

Requesting permissions should be invoked only once in the application lifetime, somwhere on the application startup or user login.

requestPermission() method should not be superseeded by the getLocation method, which results in the error described above, where result object is already submitted back to platform channel.

Workaround

Use hasPermission method before requesting device location, to avoid duplicate result object replies.

if (await location.hasPermission() == PermissionStatus.granted) {
     // get device location.
    return await location.getLocation()
 }

Check the workflow of requesting device location in your app, and fix the similarities i have pointed out.

urbanjagodic avatar Nov 30 '22 11:11 urbanjagodic