showImage function

dynamic showImage(
  1. String image, {
  2. double? width,
  3. double? height,
  4. BoxFit fit = BoxFit.contain,
  5. Alignment alignment = Alignment.center,
})

Implementation

showImage(String image, {double? width, double? height,
  BoxFit fit = BoxFit.contain, Alignment alignment = Alignment.center}){

  Widget _noImage = Container(
      width: width,
      height: height,
      padding: EdgeInsets.all(10),
      child: Image.asset("assets/noimage.png", package: 'jas_utils', fit: BoxFit.contain,));

  // if (kIsWeb)
  //   return image.isNotEmpty
  //     ? Container(
  //       width: width,
  //       height: height,
  //       child: Image.network(image, fit: fit,
  //     errorBuilder: (
  //         BuildContext context,
  //         Object error,
  //         StackTrace? stackTrace,
  //         ) {
  //       return _noImage;
  //     })) : _noImage;

  return image.isNotEmpty ? CachedNetworkImage(
      imageUrl: image,
      errorWidget: (
          BuildContext context,
          String url,
          dynamic error,
          ){
        return _noImage;
      },
      placeholder: (context, url) =>
          UnconstrainedBox(child:
          Container(
            alignment: Alignment.center,
            width: 30,
            height: 30,
            child: CircularProgressIndicator(color: aTheme.mainColor,),
          )),
      imageBuilder: (context, imageProvider) => Container(
        width: alignment == Alignment.center ? null : double.maxFinite,
        alignment: alignment,
        child: Container(
          width: width,
          height: height,
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: imageProvider,
                  fit: fit,
              )),
        ),
      )
  ) : _noImage;
}