getWidget method

  1. @override
Widget getWidget(
  1. BuildContext context
)
override

Implementation

@override
Widget getWidget(BuildContext context) {
  List<Widget> widgets = [];
  //左边的Icon
  if (leftIcon != null) {
    widgets.add(getImageWidget(leftIcon!, leftIconWidth!, leftIconHeight!));
  }
  //水平中间的文字
  if (leftIcon != null || rightIcon != null) {
    widgets.add(Container(
      margin: EdgeInsets.only(left: iconMarginRight!, right: iconMarginLeft!),
      child: getTextWidget(),
    ));
  }

  //右边的Icon
  if (rightIcon != null) {
    widgets
        .add(getImageWidget(rightIcon!, rightIconWidth!, rightIconHeight!));
  }

  if (widgets.isNotEmpty) {
    return Row(
      mainAxisAlignment: mainAxisAlignment!,
      children: widgets,
    );
  }

  //上边的icon
  if (topIcon != null) {
    widgets.add(getImageWidget(topIcon!, topIconWidth!, topIconHeight!));
  }
  //垂直中间的文字
  if (topIcon != null || bottomIcon != null) {
    widgets.add(Container(
      margin: EdgeInsets.only(top: iconMarginBottom!, bottom: iconMarginTop!),
      child: getTextWidget(),
    ));
  }
  //下面的icon
  if (bottomIcon != null) {
    widgets.add(
        getImageWidget(bottomIcon!, bottomIconWidth!, bottomIconHeight!));
  }
  if (widgets.isNotEmpty) {
    return Column(
      mainAxisAlignment: mainAxisAlignment!,
      children: widgets,
    );
  }

  //富文本
  if (richList != null && richList!.isNotEmpty) {
    List<TextSpan> list = [];
    for (var a = 0; a < richList!.length; a++) {
      var richBean = richList![a];
      var textSpan = TextSpan(
          text: richBean.text,
          recognizer: TapGestureRecognizer()
            ..onTap = () {
              //点击事件
              if (onRichClick != null) {
                onRichClick!(a, richBean);
              }
            },
          style: TextStyle(
              fontSize: richBean.textSize, color: richBean.textColor));
      list.add(textSpan);
    }
    //富文本
    return Text.rich(TextSpan(children: list));
  }
  return getTextWidget();
}