Home > database >  The argument type 'Object' can't be assigned to the parameter type 'ImageProvide
The argument type 'Object' can't be assigned to the parameter type 'ImageProvide

Time:07-30

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

CodePudding user response:

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,
    );

  • Related