Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I’m having a problem with null safety and I don’t know how to solve it please help.

var profileImage = SocialCubit.get(context).profileImage;

CircleAvatar(
  backgroundImage: profileImage == null
    ? NetworkImage('${userModel.image}')
    : FileImage(profileImage),
),

And in another class :

File? profileImage;
  var picker = ImagePicker();

  Future<void> getProfileImage() async {
    final PickedFile = await picker.pickImage(
      source: ImageSource.gallery,
    );

    if (PickedFile != null) {
      profileImage = File(PickedFile.path);
      emit(SocialProfileImagePickedSuccessState());
    } else {
      print('No image selected.');
      emit(SocialProfileImagePickedErrorState());
    }
  }

Where it gives me this error:
" The argument type ‘Object’ can’t be assigned to the parameter type ‘ImageProvider?’ "

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

please helpe me !!

>Solution :

var profileImage = SocialCubit.get(context).profileImage;

Here profile Image is defined is dynamic.. Try

File? profileImage = SocialCubit.get(context).profileImage;

or you can also cast it like this

CircleAvatar(
  backgroundImage: profileImage == null
    ? NetworkImage('${userModel.image}')
    : FileImage(profileImage) as ImageProvider?,
),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading