Imagepicker 'XFile' is not a subtype of type 'File' in type cast and Firebase Storage image upload error

I am trying to select image from gallery with imagepicker and upload it to firebasestorage. When the application runs, it gives the error "Cannot open file, path = '' (OS Error: Bad address, errno = 14) and Unhandled Exception: type 'XFile' is not a subtype of type 'File' in type cast'.

GestureDetector(
                  onTap: () => pickPhotoFromGallery(),
                  child: CircleAvatar(
                    radius: 70,
                    // ignore: unnecessary_null_comparison
                    child: (_imageFile != null)
                        ? Image.file(_imageFile)
                        : Image.asset('assets/images/icon.png'),
                  ),
                ),

Future pickPhotoFromGallery() async {
    File imageFile =
        (await _imagePicker.pickImage(source: ImageSource.gallery)) as File;

    setState(() {
      _imageFile = imageFile;
    });
  }

When I click the save button, it says "Failed assertion: line 127 pos 12: 'file.absolute.existsSync()': is not true." I am encountering the error.

onPressed: uploading ? null : () => uploadImageAndSaveItemInfo(),
  uploadImageAndSaveItemInfo() async {
    setState(() {
      uploading = true;
    });

    String imageDownloadUrl = await uploadItemImage(_imageFile);

    saveItemInfo(imageDownloadUrl);
    saveItemInfoCategory(imageDownloadUrl);
  }


  Future<String> uploadItemImage(File mFileImage) async {
    final Reference storageReference =
        FirebaseStorage.instance.ref().child("thumbnail");

    UploadTask uploadTask = storageReference
        .child(_idController.text.trim() + ".jpg")
        .putFile(mFileImage);

    String downloadUrl = await uploadTask.snapshot.ref.getDownloadURL();
    return downloadUrl;
  }

Imagepicker was working in old versions, it gives an error in the latest version.



from Recent Questions - Stack Overflow https://ift.tt/3iifxKq
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation