简体   繁体   中英

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

please helpe me

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM