Future<XFile?> appPickImage(BuildContext context) async {
XFile? photo;
final ImagePicker picker = ImagePicker();
await showModalBottomSheet(
context: context,
builder: (_) => Wrap(
spacing: 15,
children: [
const SizedBox(
height: 10,
),
ListTile(
onTap: () async {
await picker.pickImage(source: ImageSource.gallery).then((value) {
if (value != null) {
photo = value;
}
Navigator.pop(context, photo);
});
},
contentPadding: const EdgeInsets.symmetric(horizontal: 30),
leading: const Icon(CupertinoIcons.photo),
title: const Text("From Gallery"),
),
ListTile(
onTap: () async {
await picker.pickImage(source: ImageSource.camera).then((value) {
if (value != null) {
photo = value;
}
Navigator.pop(context, photo);
});
},
contentPadding: const EdgeInsets.symmetric(horizontal: 30),
leading: const Icon(CupertinoIcons.camera),
title: const Text("Take a Picture"),
),
const SizedBox(
height: 10,
),
],
),
);
return photo;
}
//start image picker
Card(
shadowColor: AppColors.transparent,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
showModalBottomSheet(
context: context,
builder: (_) => Wrap(
children: [
ListTile(
onTap: () async {
Navigator.pop(context);
final pickImage = await picker.pickImage(
source: ImageSource.gallery);
if (pickImage != null) {
_photo = File(pickImage.path);
setState(() {});
}
},
leading: const Icon(Iconsax.image),
title: const Text("From Gallery"),
),
ListTile(
onTap: () async {
Navigator.pop(context);
final pickImage = await picker.pickImage(
source: ImageSource.camera);
if (pickImage != null) {
_photo = File(pickImage.path);
setState(() {});
}
},
leading: const Icon(Iconsax.camera),
title: const Text("Take a Picture"),
),
],
));
},
child: Container(
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: AppColors.border(context),
image: _photo == null
? null
: DecorationImage(
fit: BoxFit.cover, image: FileImage(_photo!))),
child: Icon(Iconsax.gallery_add,
color:
_photo == null ? AppColors.grey : AppColors.bg(context),
shadows: _photo == null
? null
: [
const Shadow(
color: AppColors.grey,
offset: Offset(1, 1),
blurRadius: 2)
]),
),
),
),
),
shadowColor: AppColors.transparent,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
showModalBottomSheet(
context: context,
builder: (_) => Wrap(
children: [
ListTile(
onTap: () async {
Navigator.pop(context);
final pickImage = await picker.pickImage(
source: ImageSource.gallery);
if (pickImage != null) {
_photo = File(pickImage.path);
setState(() {});
}
},
leading: const Icon(Iconsax.image),
title: const Text("From Gallery"),
),
ListTile(
onTap: () async {
Navigator.pop(context);
final pickImage = await picker.pickImage(
source: ImageSource.camera);
if (pickImage != null) {
_photo = File(pickImage.path);
setState(() {});
}
},
leading: const Icon(Iconsax.camera),
title: const Text("Take a Picture"),
),
],
));
},
child: Container(
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: AppColors.border(context),
image: _photo == null
? null
: DecorationImage(
fit: BoxFit.cover, image: FileImage(_photo!))),
child: Icon(Iconsax.gallery_add,
color:
_photo == null ? AppColors.grey : AppColors.bg(context),
shadows: _photo == null
? null
: [
const Shadow(
color: AppColors.grey,
offset: Offset(1, 1),
blurRadius: 2)
]),
),
),
),
),
//end image picker
Comments
Post a Comment