Resolve and add functions to my flutter app
Budget: €8 – €30 EUR
I used an image picker that allows me to retrieve and save an image in the application folder. I'm trying to display conditionally the background of my container either in black if the image doesn't exist, or the image if it does exist
I am currently trying to check with
child: (File(widget.id + '.jpg').exists())
But this is impossible because value always pays true
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
pickImage();
},
child: (File(widget.id + '.jpg').exists())
? Container(
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(File(widget.id + ".jpg")),
fit: BoxFit.cover,
),
color: Colors.black87,
borderRadius: BorderRadius.circular(5)),
child: Align(
alignment: FractionalOffset.bottomLeft,
child: MaterialButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5),
bottomRight: Radius.circular(5),
),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
minWidth: double.infinity,
color: Colors.yellow,
onPressed: () {},
child: Text('SNAPPER')),
))
: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(5)),
child: Align(
alignment: FractionalOffset.bottomLeft,
child: MaterialButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5),
bottomRight: Radius.circular(5),
),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
minWidth: double.infinity,
color: Colors.yellow,
onPressed: () {},
child: Text('SNAPPER')),
)));
}
}
I would also like to shorten the condition? I'm calling two containers when I could use only one and condition only the background
Thanks a lot
I am currently trying to check with
child: (File(widget.id + '.jpg').exists())
But this is impossible because value always pays true
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
pickImage();
},
child: (File(widget.id + '.jpg').exists())
? Container(
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(File(widget.id + ".jpg")),
fit: BoxFit.cover,
),
color: Colors.black87,
borderRadius: BorderRadius.circular(5)),
child: Align(
alignment: FractionalOffset.bottomLeft,
child: MaterialButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5),
bottomRight: Radius.circular(5),
),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
minWidth: double.infinity,
color: Colors.yellow,
onPressed: () {},
child: Text('SNAPPER')),
))
: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(5)),
child: Align(
alignment: FractionalOffset.bottomLeft,
child: MaterialButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5),
bottomRight: Radius.circular(5),
),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
minWidth: double.infinity,
color: Colors.yellow,
onPressed: () {},
child: Text('SNAPPER')),
)));
}
}
I would also like to shorten the condition? I'm calling two containers when I could use only one and condition only the background
Thanks a lot