What a file type is it 'File$' and how can it be made to type 'File' in flutter

Viewed 869

I'm making functionality to be able to upload images to firebase storages through the Flutter Web. I need a list a files, where each file is 'File' type, but i get a type 'File$'.

import 'dart:io' as io;
 

            SpeedDial(
                animatedIconTheme: IconThemeData(size: 22.0),
                child: Icon(Icons.add),
                closeManually: false,
                children: [
                  SpeedDialChild(
                      child: Icon(Icons.photo_library),
                      label: translate('agreement.image_uploader.select_images_button', context: context),
                      onTap: () => _callAddImagesFromWeb(context)),
                ],
              )
  _callAddImagesFromWeb(BuildContext context) async {
    print('Called _callAddImagesFromWeb: upload images from web app');

    html.InputElement uploadInput = html.FileUploadInputElement();
    uploadInput.multiple = true;
    uploadInput.click();

    uploadInput.onChange.listen((changeEvent) {
      print("User added images, length: " + uploadInput.files.length.toString());
      allProcessAmount = uploadInput.files.length;
      doneProcessAmount = 0;

      uploadFile(uploadInput.files);

    });
  }

Method uploadFile get a list of Files and i need to storage each file to Firebase storage, but when i take one element from list, i get an error that ** Error: Expected a value of type 'File', but got one of type 'File$' **

  Future uploadFile(List list) async {
    // EXCEPTION IS HERE
    io.File image = list.first;

    var fileName = new DateTime.now().millisecondsSinceEpoch.toString();
    StorageReference storageReference = FirebaseStorage.instance
        .ref()
        .child('agreements/' + widget.agreement.id + '/' + fileName);

    StorageUploadTask uploadTask = storageReference.putFile(image);

    await uploadTask.onComplete;
    print('File Uploaded');
    storageReference.getDownloadURL().then((fileURL) {
      print(fileURL);
    });
  }

enter image description here

0 Answers
Related