getLoadWidget static method

Widget getLoadWidget(
  1. String? url,
  2. String imageIcon,
  3. String imageUrl,
  4. String load,
  5. Color colorBg,
  6. Color colorProgress, {
  7. double? width,
  8. double? height,
  9. Alignment? alignment,
  10. BoxFit? fit,
  11. String? package,
  12. Map<String, String>? headers,
})

Implementation

static Widget getLoadWidget(
  String? url,
  String imageIcon,
  String imageUrl,
  String load,
  Color colorBg,
  Color colorProgress, {
  double? width,
  double? height,
  Alignment? alignment,
  BoxFit? fit,
  String? package,
  Map<String, String>? headers,
}) {
  if (url?.isEmpty == false) {
    if (url!.startsWith(imageIcon)) {
      return Image.asset(
        url,
        width: width,
        height: height,
        fit: fit,
        package: package,
      );
    } else if (!url.startsWith('http')) {
      return ExtendedImage.file(
        File(url),
        width: width,
        height: height,
        fit: fit ?? BoxFit.cover,
        alignment: alignment ?? Alignment.topCenter,
        enableLoadState: true,
        loadStateChanged: ((ExtendedImageState state) {
          switch (state.extendedImageLoadState) {
            case LoadState.loading:
              if (state.loadingProgress == null) {
                return Image.asset(
                  load,
                  width: width,
                  height: height,
                  fit: fit ?? BoxFit.cover,
                  alignment: alignment ?? Alignment.center,
                  package: package,
                );
              }
              return Container(
                color: colorBg,
                child: Center(
                  child: CircularProgressIndicator(
                      valueColor:
                          AlwaysStoppedAnimation<Color>(colorProgress),
                      value: state.loadingProgress!.expectedTotalBytes != null
                          ? state.loadingProgress!.cumulativeBytesLoaded /
                              state.loadingProgress!.expectedTotalBytes!
                          : null),
                ),
              );
            case LoadState.completed:
              return state.completedWidget;
            default:
              return Image.asset(
                load,
                width: width,
                height: height,
                fit: fit ?? BoxFit.cover,
                alignment: alignment ?? Alignment.center,
                package: package,
              );
          }
        }),
      );
    } else {
      return ExtendedImage.network(
        !url.startsWith(imageUrl) && headers == null && (width ?? 0) != 0
            ? compressImageUrl(url, width: width!.toInt())
            : url,
        width: width,
        height: height,
        fit:
            fit ?? (url.startsWith(imageUrl) ? BoxFit.contain : BoxFit.cover),
        headers: headers,
        alignment: alignment ?? Alignment.topCenter,
        enableLoadState: true,
        handleLoadingProgress: true,
        loadStateChanged: ((ExtendedImageState state) {
          switch (state.extendedImageLoadState) {
            case LoadState.loading:
              if (state.loadingProgress == null) {
                return Image.asset(
                  load,
                  width: width,
                  height: height,
                  fit: fit ?? BoxFit.cover,
                  alignment: alignment ?? Alignment.center,
                  package: package,
                );
              }
              return Container(
                color: colorBg,
                child: Center(
                  child: CircularProgressIndicator(
                      valueColor:
                          AlwaysStoppedAnimation<Color>(colorProgress),
                      value: state.loadingProgress!.expectedTotalBytes != null
                          ? state.loadingProgress!.cumulativeBytesLoaded /
                              state.loadingProgress!.expectedTotalBytes!
                          : null),
                ),
              );
            case LoadState.completed:
              return state.completedWidget;
            default:
              return Image.asset(
                load,
                width: width,
                height: height,
                fit: fit ?? BoxFit.cover,
                alignment: alignment ?? Alignment.center,
                package: package,
              );
          }
        }),
      );
    }
  } else {
    return Image.asset(
      load,
      width: width,
      height: height,
      fit: fit ?? BoxFit.cover,
      alignment: alignment ?? Alignment.center,
      package: package,
    );
  }
}