【发布时间】:2020-10-31 13:36:06
【问题描述】:
在我的应用程序中,我使用了 image_picker 和 image_picker_web,但是在 iOS 上运行时它会抛出 No podspec found for 'image_picker_web' in '.symlinks/plugins/image_picker_web/ios'exception。
所以我决定不使用它并选择像How to Pick files and Images for upload with flutter web 中接受的解决方案中的文件。
选择文件的打印是正确的,但我的方法返回 null 我猜它在分配值之前返回变量。
我不知道html所以我有点迷路了..
返回选择的值我做错了什么?
FileReader reader = FileReader();
InputElement uploadInput = FileUploadInputElement();
Future<Uint8List> pickImage() async {
print('FirebaseImageStorageRepositoryWeb. pickImage() started');
// image_picker_web works on web but creates pod problems on iOS
// Uint8List imageData;
// String fileName;
// await picker.getImage(source: ImageSource.gallery).then((picked) {
// picked.readAsBytes().then((data) {
// imageData = data;
// });
// });
// image_picker // notworking on web...
//html
Uint8List imageData;
InputElement uploadInput = FileUploadInputElement();
uploadInput.click();
uploadInput.onChange.listen((e) {
// read file content as dataURL
final files = uploadInput.files;
if (files.length == 1) {
final file = files[0];
print(
'selected file: type:${file.type},name: ${file.name}, size: ${file.size}');
reader.onLoadEnd.listen((e) {
imageData = reader.result;
// return imageData; // not working
});
reader.onError.listen((fileEvent) {
print('Some Error occured while reading the file');
});
reader.readAsArrayBuffer(file);
}
});
return imageData;
}
【问题讨论】: