image function

Widget image(
  1. String source, {
  2. Color? color,
  3. double? width,
  4. double? height,
  5. BoxFit fit = BoxFit.contain,
  6. Clip clipBehavior = Clip.hardEdge,
  7. double borderRadius = 1,
  8. EdgeInsets margin = EdgeInsets.zero,
  9. String? placeholder,
  10. VoidCallback? onTap,
})

Implementation

Widget image(
  final String source, {
  final Color? color,
  final double? width,
  final double? height,
  final BoxFit fit = BoxFit.contain,
  final Clip clipBehavior = Clip.hardEdge,
  final double borderRadius = 1,
  final EdgeInsets margin = EdgeInsets.zero,
  final String? placeholder,
  final VoidCallback? onTap,
}) {
  if (source.length <= 10) {
    if (placeholder == null) {
      return SizedBox(width: width, height: height);
    } else {
      return imageAsset(
        placeholder,
        width: width,
        height: height,
        borderRadius: borderRadius,
        color: color,
        margin: margin,
        onTap: onTap,
        fit: fit,
        clipBehavior: clipBehavior,
      );
    }
  } else {
    if (source.contains("http://") || source.contains("https://")) {
      return imageNetwork(
        source,
        width: width,
        height: height,
        fit: fit,
        clipBehavior: clipBehavior,
        margin: margin,
        borderRadius: borderRadius,
        color: color,
        onTap: onTap,
        placeholder: placeholder,
      );
    } else {
      return imageAsset(
        source,
        width: width,
        height: height,
        fit: fit,
        clipBehavior: clipBehavior,
        margin: margin,
        borderRadius: borderRadius,
        color: color,
        onTap: onTap,
      );
    }
  }
}