kimageText function

Widget kimageText(
  1. String? imagePath,
  2. Widget text,
  3. ImageGravity gravity, {
  4. int marginImage = 0,
  5. int? imageWidth,
  6. int? imageHeight,
  7. int? textMaxWidth,
  8. MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center,
  9. bool isNetImage = false,
  10. Function? onTap,
})

图片+文字

Implementation

Widget kimageText(
  String? imagePath,
  Widget text,
  ImageGravity gravity, {
  int marginImage = 0,
  int? imageWidth,
  int? imageHeight,
  int? textMaxWidth,
  MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center,
  bool isNetImage = false,
  Function? onTap,
}) {
  Widget resultView;
  switch (gravity) {
    case ImageGravity.left:
      if (textMaxWidth == null) {
        resultView = Wrap(
          direction: Axis.horizontal,
          crossAxisAlignment: WrapCrossAlignment.center,
          spacing: marginImage.w,
          children: [
            kimage(isNetImage, imagePath, imageWidth, imageHeight),
            text
          ],
        );
      } else {
        resultView = Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            kimage(isNetImage, imagePath, imageWidth, imageHeight),
            LimitedBox(
              maxWidth: textMaxWidth.w,
              child: text,
            )
          ],
        );
      }
      break;
    case ImageGravity.right:
      if (textMaxWidth == null) {
        resultView = Wrap(
          direction: Axis.horizontal,
          crossAxisAlignment: WrapCrossAlignment.center,
          spacing: marginImage.w,
          children: [
            text,
            kimage(isNetImage, imagePath, imageWidth, imageHeight)
          ],
        );
      } else {
        resultView = Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            LimitedBox(
              maxWidth: textMaxWidth.w,
              child: text,
            ),
            kimage(isNetImage, imagePath, imageWidth, imageHeight)
          ],
        );
      }
      break;
    case ImageGravity.top:
      resultView = Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: mainAxisAlignment,
        children: [
          kimage(isNetImage, imagePath, imageWidth, imageHeight),
          Padding(padding: EdgeInsets.only(top: marginImage.h), child: text),
        ],
      );
      break;
    case ImageGravity.bottom:
      resultView = Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: mainAxisAlignment,
        children: [
          Padding(padding: EdgeInsets.only(bottom: marginImage.h), child: text),
          kimage(isNetImage, imagePath, imageWidth, imageHeight),
        ],
      );
      break;
  }
  if (onTap != null) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      child: resultView,
      onTap: () => {onTap()},
    );
  } else {
    return resultView;
  }
}