I'm mocking FlutterDocumentPicker using below code:
var binding = // current test binding;
const MethodChannel channel = MethodChannel('flutter_document_picker');
binding.defaultBinaryMessenger
.setMockMethodCallHandler(channel, _mockDocumentPickerHandler);
Future<Object?> _mockDocumentPickerHandler(MethodCall message) async {
if (message.method == 'pickDocument') {
final Directory tempDir = await getTemporaryDirectory();
final File file = await File(
'${tempDir.path}/doc.pdf',
).writeAsBytes(await _getBytes());
print("Selecting path for file picker ${file.path}");
if (message.arguments["isMultipleSelection"]) {
return [file.path];
} else {
return file.path;
}
} else {
throw UnimplementedError(
"Mock method ${message.method} call for method channel flutter_document_picker is not handled");
}
}
This works great in case of IO devices but not in web. As in web there is no support for getTemporaryDirectory and the return type of method is expected to be a File path(String), how to store a mock file at a temporary path and return that path?
the File selection code in flutter also expects a file path only, my query is how to mock file picking for Integration tests in flutter web?