Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Argument type 'Widget Function(BuildContext, Widget, ImageChunkEvent)' can't be assigned flutter dart

I am having the following error The argument type 'Widget Function(BuildContext, Widget, ImageChunkEvent)' can't be assigned to the parameter type 'Widget Function(BuildContext, Widget, ImageChunkEvent?)?'. I am trying to add a CircularProgressIndicator to Image.network that will show before image loads. Below is how i am implementing it


Padding(
              padding: const EdgeInsets.all(5),
              child: Builder(builder: (BuildContext context) {
                if (Config().equalsIgnoreCase(
                    "imageNetwork", widget.imageFetchType)) {
                  return CircleAvatar(
                      radius: 100,
                      child: ClipOval(
                        child: Image.network(
                          widget.picture,
                          width: 190,
                          height: 190,
                          fit: BoxFit.cover,
                          loadingBuilder: (BuildContext context, Widget child,
                          ImageChunkEvent loadingProgress){
                            if (loadingProgress == null) return child;
                            return Center(
                              child: CircularProgressIndicator(
                                value: loadingProgress.expectedTotalBytes != null
                                ? loadingProgress.cumulativeBytesLoaded /
                                loadingProgress.expectedTotalBytes
                                : null,
                              ),
                            )
                          },
                        ),
                      ),
                  // circle avatar background color
                  backgroundColor: Colors.deepOrange,);
                }

                return CircleAvatar(
                  radius: 100,
                  backgroundImage: NetworkImage(widget.picture),
                );

              }),
            )

The error comes in the following lines of code


loadingBuilder: (BuildContext context, Widget child,
                          ImageChunkEvent loadingProgress){
                            if (loadingProgress == null) return child;
                            return Center(
                              child: CircularProgressIndicator(
                                value: loadingProgress.expectedTotalBytes != null
                                ? loadingProgress.cumulativeBytesLoaded /
                                loadingProgress.expectedTotalBytes
                                : null,
                              ),
                            )
                          }

I have tried doing the following below but its still having the error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

child: (_) => Builder(builder: (BuildContext context)

>Solution :

ImageChunkEvent should be nullable hence use ImageChunkEvent?.

You should also add a semi-colon after the Center

Like so:

   loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
        if (loadingProgress == null) return child;
        return Center(
          child: CircularProgressIndicator(
            value: loadingProgress.expectedTotalBytes != null
                ? loadingProgress.cumulativeBytesLoaded /
                    loadingProgress.expectedTotalBytes!
                : null,
          ),
        );
      },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading