kimageText function
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,
图片+文字
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;
}
}