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

when i try to import 'dart.io' i face this problem or when i delete 'dart.io' i face undefined class 'File'

File file;
  getPhoto() async {
    Navigator.pop(context);
  File file =  await ImagePicker.platform.pickImage(
      source: ImageSource.gallery,
      maxHeight: 675,
      maxWidth: 960,
    );
  }
~~~!


Solution 1:[1]

pickImage returns a PickedFile? and not File

Use this to get a file:

  File? file;
  getPhoto() async {
    Navigator.pop(context);
    final pickedImage = await ImagePicker.platform.pickImage(
      source: ImageSource.gallery,
      maxHeight: 675,
      maxWidth: 960,
    );
    if(pickedImage != null){
      file = File(pickedImage.path);
    }
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Josteve