fromLocal static method

Widget fromLocal(
  1. String assetName, {
  2. double? width,
  3. double? height,
  4. Color? color,
  5. BoxDecoration? decoration,
  6. EdgeInsets? padding,
  7. EdgeInsets? margin,
  8. bool isCircle = false,
  9. BoxFit fit = BoxFit.contain,
  10. bool backOffSizing = true,
  11. bool enableMirror = false,
})

Create an image from assetName of your local assets

backOffSizing determine whether to use backOff dimension if not set eg. if width is not set, use height instead enableMirror will make your image mirrored!

Implementation

static Widget fromLocal(
  String assetName, {
  double? width,
  double? height,
  Color? color,
  BoxDecoration? decoration,
  EdgeInsets? padding,
  EdgeInsets? margin,
  bool isCircle = false,
  BoxFit fit = BoxFit.contain,
  bool backOffSizing = true,
  bool enableMirror = false,
}) {
  bool isSvg = assetName.split('.')[1] == 'svg';
  double? measuredHeight = height ?? (backOffSizing ? width : null);
  double? measuredWidth = width ?? (backOffSizing ? height : null);
  Widget image;
  if (isSvg) {
    image = SvgPicture.asset(
      assetName,
      height: measuredHeight,
      width: measuredWidth,
      color: color,
      fit: fit,
      placeholderBuilder: (context) {
        return SizedBox(width: measuredWidth, height: measuredHeight);
      },
    );
  } else {
    image = Image.asset(
      assetName,
      width: measuredWidth,
      height: measuredHeight,
      color: color,
      fit: fit,
    );
  }
  return Container(
    padding: padding,
    margin: margin,
    decoration: isCircle == true ? _circle : decoration,
    child: image,
  ).makeMirror(enableMirror);
}