I was trying to create a simple file uploader for a project in flutter, meant to upload images on a Firebase storage bucket, but I can't find a way to select the file type.
I've read the not-so-exhaustive documentation of Dart, but I didn't find anything similar to what I'm trying to do.
static Future<Uri> showUploadDialog(
firebase.StorageReference filePath, String fileName) async {
Completer completer = Completer();
InputElement uploadInput = FileUploadInputElement();
uploadInput.click();
uploadInput.onChange.listen(
(changeEvent) {
final file = uploadInput.files.first;
final reader = FileReader();
reader.onLoadEnd.listen(
(loadEndEvent) async {
debugPrint("Selected the file to be uploaded.");
// Here we handle the file.
completer.complete(uploadFile(file, filePath, fileName));
},
);
reader.readAsDataUrl(file);
},
);
return await completer.future;
}
My aim is to be able to see a FileUploadInputElement which doesn't allow me to upload a file different from an image file (with an image specific extension).