buildFutureBuilderImage method

Widget buildFutureBuilderImage(
  1. String url
)

Implementation

Widget buildFutureBuilderImage(String url) {
  return FutureBuilder(
    future: Future.delayed(imageLoadingDelay),
    builder: (context, snapshot) {
      return CachedNetworkImage(
        imageUrl: url,
        fit: fit,
        imageBuilder: (context, provider) {
          return Container(
            height: height,
            width: width,
            decoration: BoxDecoration(
              image: DecorationImage(image: provider, fit: fit),
            ),
          );
        },
        progressIndicatorBuilder: (context, url, downloadProgress) {
          final progress = downloadProgress.progress ?? 0.0;

          switch (loadingType) {
            case LoadingType.progress:
              return Center(
                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,
                    ),
                  ],
                ),
              );

            case LoadingType.linear:
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  LinearProgressIndicator(
                    value: progress,
                    color: loadingColor,
                  ),
                  const SizedBox(height: 6),
                  Txt(
                    '${(progress * 100).toStringAsFixed(0)}%',
                    fontSize: 12,
                    textColor: Clr.colorPrimary,
                  ),
                ],
              );

            case LoadingType.shimmer:
              return Shimmer.fromColors(
                baseColor: shimmerBaseColor,
                highlightColor: shimmerHighlightColor,
                child: Container(
                  width: width,
                  height: height,
                  color: Colors.white,
                ),
              );
          }
        },
        errorWidget: (context, url, error) =>
        errorWidget ??
            Container(
              height: height,
              width: width,
              decoration: pBoxDecoration(
                borderRadius: borderRadius ??
                    BorderRadius.circular(radius ?? Siz.defaultRadius),
              ),
              child: _buildError(),
            ),
      );
    },
  );
}