A value of type 'XFile' can't be assigned to a variable of type File

117 Views Asked by At

My source code generates two errors:

  1. A value of type 'XFile' can't be assigned to a variable of type 'File'.
  2. Instance member 'pickImage' can't be accessed using static access.at

Here is my source code:

`

  String _tweetText;
  File _pickedImage;
  bool _loading = false;

  handleImageFromGallery() async {
    try {
      File imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
      if (imageFile != null) {
        setState(() {
          _pickedImage = imageFile;
        });
      }
    } catch (e) {
      print(e);
    }
  }

`

I am new to flutter and could not solve these issues so far.

1

There are 1 best solutions below

0
Abdullatif Eida On

To solve fiest issue write this code

fileVar=File(XfileVar)

To solve second issue you have to assign avarible to _pickedImage or make it null by adding ?