gmImage function

Widget gmImage(
  1. String? url, {
  2. String? localPath,
  3. double? width,
  4. double? height,
  5. BoxFit? fit = BoxFit.contain,
  6. BorderRadius? borderRadius,
})

Implementation

Widget gmImage(
  String? url, {
  String? localPath,
  double? width,
  double? height,
  BoxFit? fit = BoxFit.contain,
  BorderRadius? borderRadius,
}) {
  return ClipRRect(
    borderRadius: borderRadius ?? BorderRadius.circular(0), // 设置圆角
    child: url == null || url.isEmpty
        ? (localPath == null
            ? SizedBox.shrink()
            : Image.asset(
                localPath!,
                width: width,
                height: height,
                fit: fit,
              ))
        : CachedNetworkImage(
            imageUrl: url,
            width: width,
            height: height,
            fit: fit,
            placeholder: (context, url) => const SizedBox.shrink(),
            errorWidget: (context, url, error) => localPath == null
                ? SizedBox.shrink()
                : Image.asset(
                    localPath!,
                    width: width,
                    height: height,
                    fit: fit,
                  ),
          ),
  );
}