pickimage’ is deprecated and shouldn’t be used. use imagepicker.getimage() method instead

Hritika Agarwal
Oct 31, 2020

Declare your getImage method->

PickedFile imageFile;

Future getImage(int type) async {
PickedFile pickedImage = await ImagePicker().getImage(
source: type == 1 ? ImageSource.camera : ImageSource.gallery,
imageQuality: 50);
return pickedImage;
}

Display your Picked image in the container ->

Expanded(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageFile == null
? AssetImage('assets/illustrations/name_contact.png')
: FileImage(File(imageFile.path)),
fit: BoxFit.cover)),
),
),

Calling the GetImage Method->

new ListTile(
leading: new Icon(
Icons.photo_library,
),
title: new Text(
'Galary',
onTap: () async {
final tmpFile = await getImage(2);

setState(() {
imageFile = tmpFile;
});
}),

Similarly we can call GetImage method for Camera input with input index 1 .

All done!

--

--