0

我有以下错误The argument type 'Widget Function(BuildContext, Widget, ImageChunkEvent)' can't be assigned to the parameter type 'Widget Function(BuildContext, Widget, ImageChunkEvent?)?'.,我试图添加一个CircularProgressIndicatorImage.network在图像加载之前显示的错误。下面是我如何实现它


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),
                );

              }),
            )

错误出现在以下代码行中


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,
                              ),
                            )
                          }

我已尝试执行以下操作,但仍然出现错误

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

4

1 回答 1

1

ImageChunkEvent应该可以为空,因此使用ImageChunkEvent?.

您还应该在Center

像这样:

   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,
          ),
        );
      },
于 2022-01-22T08:45:16.610 回答