Im trying to displayed user images in flutter .At the moment user can open camera or gallery and pick or take a picture . And I also uploaded it on storage .But how can I displayed this pictures in my app ? Thats the involvement methods . So here is where I want to display my picture :
child: CircleAvatar(
radius: 70,
child:_pickedImage ==null ?Text("Picture"):null,
backgroundImage: _pickedImage!=null?FileImage(_pickedImage):null,
),
This is how I create the picture load it and so one ...
Future _loadPicker(ImageSource source) async {
final picked = await picker.getImage(source: source);
if (this.mounted) { // This checks if the widget is still in the tree
setState(() {
setState(() {
if (picked != null) {
_cropImage(picked);
} else {
print('No image selected.');
}
});
//Navigator.pop(context);
});
}
}
_cropImage(PickedFile picked) async {
File cropped = await ImageCropper.cropImage(
sourcePath: picked.path,
aspectRatioPresets: [
CropAspectRatioPreset.original,
CropAspectRatioPreset.ratio16x9,
CropAspectRatioPreset.ratio5x4
],
maxWidth: 800,
);
if (cropped != null) {
setState(() {
_pickedImage = cropped;
});
final addDir= await syspath.getApplicationDocumentsDirectory();
final filename= path.basename(cropped.path);
final savedImage = await cropped.copy('${addDir.path}/$filename');
}
}
void _showPickOptionsDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: Text("Pick from Gallery"),
onTap: () {
_loadPicker(ImageSource.gallery);
Navigator.pop(context);
},
),
ListTile(
title: Text("Take a picture"),
onTap: () {
_loadPicker(ImageSource.camera);
Navigator.pop(context);
},
)
],
),
),
);
}
This is what im using on my on saved button to save the picture into storage:
final ref= FirebaseStorage.instance.ref().child('user_profile_pictures').child(user.uid+'.jpg');
await ref.putFile(_pickedImage).whenComplete;
Hope anyone can help thanks .