Home > database >  Error related to The argument type 'Object' can't be assigned to the parameter type &
Error related to The argument type 'Object' can't be assigned to the parameter type &

Time:07-30

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?' "

please helpe me !!

CodePudding user response:

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?,
),
  • Related