buildFutureBuilderImage method

Widget buildFutureBuilderImage()

Implementation

Widget buildFutureBuilderImage() {
  return FutureBuilder(
      future: Future.delayed(imageLoadingDelay),
      builder: (context, asyncSnapshot) {
        return CachedNetworkImage(
          imageUrl: imagePath ?? defaultImage,
          imageBuilder: (context, provider) {
            return Container(
              height: height,
              width: width,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: provider,
                  fit: fit,
                ),
              ),
            );
          },
          progressIndicatorBuilder: (context, url, downloadProgress) {
            double progress = downloadProgress.progress != null && downloadProgress.progress! > 0.0 && downloadProgress.progress! < 1.0 ? downloadProgress.progress! : 0.0;
            if (progress < 0.1) {
              return Center(
                child: Container(
                  height: height,
                    width: width,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    // borderRadius: (borderRadius ?? BorderRadius.circular(radius ?? Siz.defaultRadius)),
                  ),
                  child: Center(
                    child: LoadingPro(
                      valueColor: loadingColor ?? Clr.colorPrimary,
                    ),
                  ),
                ),
              );
            }
            return Center(
              child: CircleAvatar(
                backgroundColor: loadingBgColor,
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    SizedBox(
                      height: height,
                      width: width,
                      child: CircularProgressIndicator(
                        value: progress,
                        strokeWidth: 4,
                        color: loadingColor,
                      ),
                    ),
                    Txt('${(progress * 100).toStringAsFixed(0)}%',
                        fontSize: 12, textColor: Clr.colorPrimary),
                  ],
                ),
              ),
            );
          },
          errorWidget: (context, url, error) =>
              errorWidget ??
              Container(
                height: height,
                width: width,
                decoration: pBoxDecoration(
                  borderRadius: borderRadius ?? BorderRadius.circular(radius ?? Siz.defaultRadius),
                ),
                child: Image.asset(
                  defaultImage,
                  width: width,
                  height: height,
                  fit: fit,
                ),
              ),
        );
      });
}