I am using Image Package to resize an image (actually down size) after picking it up using file_picker package but when I try to show it in CircleAvatar Widget I got this runtime error:
type 'Image' is not a subtype of type 'ImageProvider' in type cast
here are some of my imports and fields:
import 'package:image/image.dart' as IM;
//....
IM.Image? profilePhoto;
here is my function that gets the image and then resize it:
void changePhoto() async {
final result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['JPEG', 'PNG', 'GIF', 'WebP', 'BMP', 'WBMP']);
if (result == null) return;
setState(() {
IM.Image image =
IM.decodeImage(File(result.files.first.path!).readAsBytesSync()) as IM.Image;
IM.Image thumbnail = IM.copyResize(image, width: 125);
// File('out/thumbnail-test.png').writeAsBytesSync(IM.encodePng(thumbnail));
profilePhoto = thumbnail;
});
// await new Future.delayed(const Duration(seconds: 5));
}
and here is my widget code:
child: CircleAvatar(
backgroundImage: profilePhoto != null
? profilePhoto as ImageProvider<Object>
: AssetImage('images/technician_avatar.jpg')
as ImageProvider,
radius: 80,
)
Just a side note: Later I wanna upload it to cloud Firestore. I tried to use image_picker package but it has an annoying thing that it changes the name of the file and I couldn't find a way around it.