I am getting error in the image and error is:
The argument ‘Image’ type can’t be assigned to a parameter type ‘ImageProvider'<object>
Why this error is coming?
I have this code:
ListTile(
title: Text('Manzar'),
subtitle: Text('Where are you from'),
trailing: Text('6:30 pm'),
leading: CircleAvatar(
`your text`,
backgroundImage: Image.asset('assets/images/pic.jpg'),
),
);
3
Answers
Do This :-
ImageProvider accept AssetImage as perameter
You are passing an object of type
Image
to the field backgroundImage, which is expecting an objet of typeImageProvider
.Image
is a widget class, which means it is a Flutter widget used to render images. This is what it is actually usingCircleAvatar
underneath to represent the background image.ImageProvider
is interface-class which is used to provide information to widgets on the data of an image (retrieved from a file, asset, network, …)In your case, you shall just provide your asset image as an
ImageProvider
of typeAssetImage
:The error you’re encountering is because the backgroundImage property of CircleAvatar expects an object of type ImageProvider, but you’re providing it with an Image widget directly. Fix this by this way: