urlToImage function

Widget urlToImage(
  1. String? link, {
  2. double? width,
  3. double? height,
})

Implementation

Widget urlToImage(String? link, {double? width, double? height}) {
  Widget inner = Container();
  if (link == null) {
    return SizedBox(
      width: width,
      height: height,
      child: inner,
    );
  } else {
    final url = Uri.tryParse(link);
    if (url == null) {
      return SizedBox(
        width: width,
        height: height,
        child: inner,
      );
    }
    if (url.data != null && url.data!.isBase64) {
      inner = Image.memory(url.data!.contentAsBytes(), gaplessPlayback: true);
    } else if (url.isAbsolute) {
      if (UrlTypeHelper.getType(url) == UrlType.video) {
        inner = VideoWidget(uri: url);
      } else {
        inner = Image.network(link, gaplessPlayback: true);
      }
    }

    return SizedBox(
      width: width,
      height: height,
      child: inner,
    );
  }
}