incrediblezayed / file_saver

A simple flutter plugin for saving files in all platforms
https://pub.dev/packages/file_saver
BSD 3-Clause "New" or "Revised" License
75 stars 103 forks source link

Crash caused by `java.lang.IllegalStateException: Reply already submitted error` #92

Closed RobertOdrowaz closed 9 months ago

RobertOdrowaz commented 10 months ago

Plugin can cause app crash by submitting method channel result multiple times after saveAs action. This behaviour is caused by incorrect handling of activity result in android code.

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
    if (requestCode == SAVE_FILE && resultCode == Activity.RESULT_OK && data?.data != null) {
        Log.d(TAG, "Starting file operation")
        completeFileOperation(data.data!!)
    } else {
        Log.d(TAG, "Activity result was null")
        result?.success(null)
        return false
    }
    return true
}

More specifically the issue is that else block will be called whenever requestCode doesn't match SAVE_FILE. This means that it will be called and submit success also for results from activities started by other plugins in my case share_plus (in some cases the other plugin may handle the result first which prevents the crash).

I will open a PR with a fix for this issue shortly

incrediblezayed commented 9 months ago

Merged this, will be publishing today