有没有一种方法可以在文本小部件中添加边框而不将其包装在容器小部件中

时间:2020-04-27 02:25:35

标签: flutter flutter-widget text-widget flutter-text

enter image description here,请删除容器窗口小部件并向文本窗口小部件添加边框半径,或者是否可以使文本窗口小部件和容器窗口小部件共同响应更改(意味着:当文本为空时该容器不应显示)

   child: Container(
                     padding: EdgeInsets.fromLTRB(25.0, 0, 10.0, 0),
                     decoration: ShapeDecoration(
                     color: Colors.grey[850],
                     shape: RoundedRectangleBorder(
                     side: BorderSide(
                     width: 2.0,
                     style: BorderStyle.solid,
                     color: Colors.black,
                                        ),
                     borderRadius:
                     BorderRadius.all(Radius.circular(15.0)),
                                      ),
                                    ),
                     child: Text(
                     costOfSales,
                     style: TextStyle(
                    `enter code here` color: Colors.white,
                     fontSize: 25.0,
                                      ),
                                    )),

1 个答案:

答案 0 :(得分:0)

Widget build(BuildContext context) {
    var costOfSales = "\$99";

    return costOfSales == null
        ? Container()
        : Container(
            padding: EdgeInsets.fromLTRB(25.0, 0, 10.0, 0),
            decoration: ShapeDecoration(
              color: Colors.grey[850],
              shape: RoundedRectangleBorder(
                side: BorderSide(
                  width: 2.0,
                  style: BorderStyle.solid,
                  color: Colors.black,
                ),
                borderRadius: BorderRadius.all(Radius.circular(15.0)),
              ),
            ),
            child: Text(
              costOfSales,
              style: TextStyle(
                color: Colors.white,
                fontSize: 25.0,
              ),
            ),
          );
  }