Trying to upload images to firebase storage after picking images in flutter web as follows:
void uploadImage({@required Function(File file) onSelected}) {
print('selecting image');
InputElement uploadInput = FileUploadInputElement()
..accept = 'image/*'; //it will upload only image
uploadInput.click();
uploadInput.onChange.listen((event) {
final file = uploadInput.files.first;
final reader = FileReader();
reader.readAsDataUrl(file);
reader.onLoadEnd.listen((event) {
onSelected(file);
});
});
//selected image
}
void uploadStorage() {
//upload selected image to Firebase storage
final dateTime = DateTime.now();
final path = 'CategoryImage/$dateTime';
uploadImage(onSelected: (file) {
if (file != null) {
setState(() {
_fileNameTextController.text = file.name;
_imageSelected=false;
_url = path;
});
Reference firebaseStorageRef = FirebaseStorage.instance.ref('CategoryImage/$dateTime').child(file.name);
UploadTask uploadTask = firebaseStorageRef.putFile(file);
uploadTask.whenComplete(() async{
String imgUrl = await firebaseStorageRef.getDownloadURL();
});
// fb.storage().refFromURL('gs://flutter-grocery-app-ca3ef.appspot.com').child(path).put(file);
}
});
}
But it returns following error:
error: The argument type 'File (where File is defined in C:\src\flutter\bin\cache\pkg\sky_engine\lib\html\html_dart2js.dart)' can't be assigned to the parameter type 'File (where File is defined in C:\src\flutter\bin\cache\pkg\sky_engine\lib\io\file.dart)'. (argument_type_not_assignable at [grocery_app_admin] lib\widgets\category\category_upload_widget.dart:180)
I looked at some solutions suggesting that there is a conflict between dart:html and dart:io so importing them separately but that didn't work either.