goderbauer / contact_picker

A Flutter plugin for picking a contact from the address book.
BSD 3-Clause "New" or "Revised" License
77 stars 109 forks source link

If multiple requests are made, it results in a crash because pendingResult is set to null #14

Open kdheepak opened 5 years ago

kdheepak commented 5 years ago

I had to modify the following

  @Override
  public void onMethodCall(MethodCall call, Result result) {
    if (call.method.equals("selectContact")) {
      if (pendingResult != null) {
        pendingResult.error("multiple_requests", "Cancelled by a second request.", null);
        pendingResult = null;
      }
      pendingResult = result;

      Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
      activity.startActivityForResult(i, PICK_CONTACT);
    } else {
      result.notImplemented();
    }
  }

to this instead for it to work

  @Override
  public void onMethodCall(MethodCall call, Result result) {
    if (call.method.equals("selectContact")) {
      if (pendingResult == null) {
        pendingResult = result;
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
        activity.startActivityForResult(i, PICK_CONTACT);
      } else {
        Log.v("ContactPickerPlugin", "Multiple requests may have been made");
      }
    } else {
      result.notImplemented();
    }
  }