Temporary workaround for #49365 (Flutter)

Adds temporary workaround for (#49365)(https://github.com/flutter/flutter/issues/49365) until 1.14.6 lands on stable channel.
This commit is contained in:
Miguel Ruivo 2020-03-15 14:23:41 +00:00
parent a9cc55f5f5
commit cabddf7790
3 changed files with 22 additions and 15 deletions

View File

@ -1,3 +1,7 @@
## 1.5.0+1
* Adds temporary workaround for (#49365)(https://github.com/flutter/flutter/issues/49365) until 1.14.6 lands on stable channel.
## 1.5.0
* **Breaking change:** Refactored `FileType` to match lower camelCase Dart guideline (eg. `FileType.ALL` now is `FileType.all`);

View File

@ -60,7 +60,6 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
public boolean onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
new Thread(new Runnable() {
@Override
public void run() {
@ -80,9 +79,9 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
currentItem++;
}
if (paths.size() > 1) {
FilePickerDelegate.this.finishWithSuccess(paths);
finishWithSuccess(paths);
} else {
FilePickerDelegate.this.finishWithSuccess(paths.get(0));
finishWithSuccess(paths.get(0));
}
} else if (data.getData() != null) {
final Uri uri = data.getData();
@ -95,26 +94,27 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
if (fullPath != null) {
Log.i(FilePickerDelegate.TAG, "Absolute file path:" + fullPath);
FilePickerDelegate.this.finishWithSuccess(fullPath);
finishWithSuccess(fullPath);
} else {
FilePickerDelegate.this.finishWithError("unknown_path", "Failed to retrieve path.");
finishWithError("unknown_path", "Failed to retrieve path.");
}
} else {
FilePickerDelegate.this.finishWithError("unknown_activity", "Unknown activity error, please fill an issue.");
finishWithError("unknown_activity", "Unknown activity error, please fill an issue.");
}
} else {
FilePickerDelegate.this.finishWithError("unknown_activity", "Unknown activity error, please fill an issue.");
finishWithError("unknown_activity", "Unknown activity error, please fill an issue.");
}
}
}).start();
return true;
} else if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_CANCELED) {
Log.i(TAG, "User cancelled the picker request");
this.finishWithSuccess(null);
finishWithSuccess(null);
return true;
} else if (requestCode == REQUEST_CODE) {
this.finishWithError("unknown_activity", "Unknown activity error, please fill an issue.");
finishWithError("unknown_activity", "Unknown activity error, please fill an issue.");
}
return false;
}
@ -127,7 +127,7 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
if (permissionGranted) {
this.startFileExplorer();
} else {
this.finishWithError("read_external_storage_denied", "User did not allowed reading external storage");
finishWithError("read_external_storage_denied", "User did not allowed reading external storage");
}
return true;
@ -159,7 +159,7 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
this.activity.startActivityForResult(intent, REQUEST_CODE);
} else {
Log.e(TAG, "Can't find a valid activity to handle the request. Make sure you've a file explorer installed.");
this.finishWithError("invalid_format_type", "Can't handle the provided file type.");
finishWithError("invalid_format_type", "Can't handle the provided file type.");
}
}
@ -167,7 +167,7 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
public void startFileExplorer(final String type, final boolean isMultipleSelection, final MethodChannel.Result result) {
if (!this.setPendingMethodCallAndResult(result)) {
FilePickerDelegate.finishWithAlreadyActiveError(result);
finishWithAlreadyActiveError(result);
return;
}
@ -183,8 +183,11 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
}
private void finishWithSuccess(final Object data) {
this.pendingResult.success(data);
this.clearPendingResult();
// Temporary fix, remove this null-check after Flutter Engine 1.14 has landed on stable
if (this.pendingResult != null) {
this.pendingResult.success(data);
this.clearPendingResult();
}
}
private void finishWithError(final String errorCode, final String errorMessage) {

View File

@ -1,7 +1,7 @@
name: file_picker
description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support.
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
version: 1.5.0
version: 1.5.0+1
dependencies:
flutter: