alann-maulana / flutter_beacon

An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
Apache License 2.0
117 stars 144 forks source link

Plugin crashes on location permission request #29

Closed tomwyr closed 4 years ago

tomwyr commented 4 years ago

In a specific scenario requesting location permission causes application to crash:

  1. Open app for the first so user is asked to enable location by the system.
  2. Call initializeScanning that also requests location permissions.
  3. Second request returns a result with empty permission arrays that causes method call handler to throw an exception (see below).
  4. When user grants/rejects permission then plugin catches also that result and attempts to post success/error on flutterResult instance (which is not set to null since the initialize method failed before reaching the code that clears it).
  5. Plugin crashes with java.lang.IllegalStateException: Reply already submitted.

\ This is the place in code that throws initially because of empty permissions and grantResults arrays:

public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  boolean locationServiceAllowed = false;
  String permission = permissions[0];
  ...
}

Which results in the following exception:

I/flutter (11033): Caught error: PlatformException(error, length=0; index=0, null)
I/flutter (11033): #0      StandardMethodCodec.decodeEnvelope 
package:flutter/…/services/message_codecs.dart:569
I/flutter (11033): #1      MethodChannel.invokeMethod 
package:flutter/…/services/platform_channel.dart:321
I/flutter (11033): <asynchronous suspension>
I/flutter (11033): #2      FlutterBeacon.initializeScanning
package:flutter_beacon/flutter_beacon.dart:54
I/flutter (11033): <asynchronous suspension>
tomwyr commented 4 years ago

I noticed that the issue doesn't seem to appear on current master branch. Do you plan to update the pub package anytime soon?

alann-maulana commented 4 years ago

Hi @tomwyr

Thanks for your PR, like you said I'm already fixing it on master branch. For last couple of months, I am heavily using it on my projects. Sometimes I do a lot of breaking changes, add some functionality, fixing bugs, improving scanning process, making it easy to use and integrate within your flutter projects etc.

I hope I can publish it soon after finishing my current projects :D