retrieveIconWidget function

Widget? retrieveIconWidget(
  1. MultiSourceIconModel icon, [
  2. double? size,
  3. bool useIconFonts = false,
  4. Color? themeColor,
])

Implementation

Widget? retrieveIconWidget(
  MultiSourceIconModel icon, [
  double? size,
  bool useIconFonts = false,
  Color? themeColor,
]) {
  if (!icon.show) return null;
  final Color? color = icon.color?.toFlutterColor() ?? themeColor;
  switch (icon.type) {
    case IconTypeEnum.icon:
      if (icon.icon == null) return null;

      // Using SVG icon instead of Flutter's Icon widget to reduce the SDK.
      return SvgIcon(
        icon: icon.icon!,
        size: size ?? icon.size ?? kDefaultIconSize,
        color: color,
      );
    case IconTypeEnum.image:
      if (icon.iconImage == null) return null;
      if (color != null && color.opacity == 0) {
        // when opacity is zero, we need to display original colors of
        // the image icon which `ImageIcon` widget cannot do. So we
        // use the raw Image widget.
        if (icon.isSvgImage) {
          return SvgPicture.network(
            icon.iconImage!,
            width: size ?? icon.size ?? kDefaultIconSize,
            height: size ?? icon.size ?? kDefaultIconSize,
          );
        }
        return SizedBox.square(
          dimension: size ?? icon.size ?? kDefaultIconSize,
          child: Image.network(
            icon.iconImage!,
            // scale: icon.scale,
            // color: color,
          ),
        );
      } else {
        if (icon.isSvgImage) {
          return SvgIconImage(
            url: icon.iconImage!,
            size: size ?? icon.size,
            color: color,
          );
        }
        return ImageIcon(
          NetworkImage(icon.iconImage!, scale: icon.scale),
          size: size ?? icon.size,
          color: color,
        );
      }
  }
}