Into my app users cant pick up picture and place it into the app, not the image that I need to place is a background image of the circleavatar. I built throught the package: image_picker a screen where image can be picked up by the phone but as I cant place the image into the backgroundof the circle avatar. this is my code:
File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
and build method:
_image == null ? CircleAvatar(
radius: 60,
backgroundColor: Colors.yellow,
child: Text(IfUserProfile.firstname[0],),
): CircleAvatar(
radius: 60,
backgroundColor: Colors.yellow,
child: Image.file(_image),),
SizedBox(
height: 4,
),
GestureDetector(
onTap: getImage,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [Icon(Icons.add_a_photo,color: Colors.white,size: 18,),
Text(' Aggiungi un immagine profilo',style: TextStyle(fontSize: 10,color: Colors.white),),
]),
),
CircleAvatar
has backgroundImage
attribute. try like below,
CircleAvatar(
..
backgroundImage: FileImage(_image),
),
CircleAvatar has an attribute just for this. Try:
CircleAvatar(
...
backgroundImage: ...,
);
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.