Click here to Skip to main content
15,609,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Add Image'),
        actions: [
            onPressed: () {
              setState(() {
                uploading = true;
              uploadFile().whenComplete(() => Navigator.of(context).pop());
            child: Text(
              style: TextStyle(color:,
      body: Stack(children: [
            itemCount: _image.length + 1,
                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(
                              DecorationImage(image: FileImage(_image[i - 1]))),
            ? Center(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                        child: Text('uploading...',
                            style: TextStyle(fontSize: 20))),
                      value: val,
                      valueColor: AlwaysStoppedAnimation<Color>(,
            : Container()

choose image function :

chooseImage() async {
    final pickedFile = await picker.pickImage(source:;
    setState(() {
    if (pickedFile!.path == null) retrieveLostData();

What I have tried:

I tried onPressed: chooseImage; but it still did not work,
wseng 30-Jan-22 7:16am    
perhaps chooseImage method not getting called?
Kavya Bhargava 30-Jan-22 8:58am    
Could you show how can i make that change,would be helpful
wseng 30-Jan-22 12:24pm    
maybe add some print function in chooseImage, check whether the method is called.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900