Search code examples
androidflutterdartflutter-image

The argument type 'Object' can't be assigned to the parameter type 'ImageProvider<Object>?


Code

PickedFile? _imageFile;
final ImagePicker _picker = ImagePicker();
    


    CircleAvatar(
       radius: 80.0,
       backgroundImage: _imageFile == null
       ? AssetImage('assets/person.png')
       : FileImage(File(_imageFile.path))
  ),

The argument type 'Object' can't be assigned to the parameter type 'ImageProvider?

Guys can anyone help me to solve this error The Asset Image is working fine but in the FileImage it shows an error I also tried with importing the dart:io pakage but this also does not work


Solution

  • Do it this way

    backgroundImage: _imageFile == null
        ? AssetImage('assets/person.png')
        : FileImage(File(_imageFile!.path)) as ImageProvider,
    

    Also try using

      XFile? _imageFile;
     ...
     final pickedFile = await _picker.pickImage(
          source: source,
        );