Home > Net >  The argument type 'XFile' can't be assigned to the parameter type 'File'
The argument type 'XFile' can't be assigned to the parameter type 'File'

Time:08-11

Please, can anyone help rewrite this code, don't know what I'm getting wrong.

 Widget _decideImageView(){
        
        if(imageFile == null) {
        return Text("No Image Selected!");} 
        else {
        Image.file(imageFile!,width: 400,height: 400,);
        }
        return Text("No Image Selected!");
  }

CodePudding user response:

Change File? imageFile; to XFile? imageFile;

Use Image.file(File(imageFile!.path), from dart:io

 XFile? imageFile;
  _openCamera(BuildContext context) async {
    imageFile = await ImagePicker().pickImage(source: ImageSource.camera);
    setState(() {});
    Navigator.of(context).pop();
  }

  Widget _decideImageView() {
    if (imageFile == null) {
      return Text("No Image Selected!");
    } else {
      return Image.file(
        File(imageFile!.path),
        width: 400,
        height: 400,
      );
    }
  }

  • Related