I built an image picker after learning in a course. I am not getting any errors in the debug console or in the build. I am trying to click it but it is not working. I made another image picker in a similar manner in same app but that did not gave any error
My add image screen:
class _AddImageState extends State<AddImage> {
bool uploading = false;
double val = 0;
CollectionReference? imgRef;
firebase_storage.Reference? ref;
List<File> _image = [];
final picker = ImagePicker();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add Image'),
actions: [
ElevatedButton(
onPressed: () {
setState(() {
uploading = true;
});
uploadFile().whenComplete(() => Navigator.of(context).pop());
},
child: Text(
'Upload',
style: TextStyle(color: Colors.red),
),
)
],
),
body: Stack(children: [
GridView.builder(
itemCount: _image.length + 1,
gridDelegate:
SliverGridDelegateWithMaxCrossAxisExtent(maxCrossAxisExtent: 1),
itemBuilder: (ctx, i) {
return i == 0
? Center(
child: IconButton(
onPressed: () {
!uploading ? chooseImage() : null;
},
icon: Icon(Icons.add)),
)
: Container(
margin: EdgeInsets.all(3),
decoration: BoxDecoration(
image:
DecorationImage(image: FileImage(_image[i - 1]))),
);
}),
uploading
? Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text('uploading...',
style: TextStyle(fontSize: 20))),
CircularProgressIndicator.adaptive(
value: val,
valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
)
],
),
)
: Container()
]),
);
}
choose image function :
chooseImage() async {
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
setState(() {
_image.add(File(pickedFile!.path));
});
if (pickedFile!.path == null) retrieveLostData();
}
What I have tried:
I tried onPressed: chooseImage; but it still did not work,