Used ImagePicker to select an image in gallery. Worked but no image is desplayed. ERROR : Unhandled Exception: type 'XFile' is not a subtype of type 'File' in type cast
Below my code :
class _RegisterScreenState extends State {
File image;
String imgUrl;
final imagePicker = ImagePicker();
Future getImage() async {
File img = await imagePicker.pickImage(
source: ImageSource.gallery);
setState(() {
image = img as File;
});
}
child: CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
backgroundImage: image != null
? Image.file(image)
: NetworkImage(
"https://cdn-icons-png.flaticon.com/512/1177/1177568.png"),
),
ERROR : Unhandled Exception: type 'XFile' is not a subtype of type 'File' in type cast
I am on :
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
image_picker: ^0.8.4+2
path_provider: ^2.0.5