如何在 Flutter 中为容器小部件加下划线

MeL*_*ine 6 widget underline flutter

我试图在我的 Flutter 应用程序中强调一个容器。到目前为止,当我使用以下代码时,我实现了某种基础:

    Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: Padding(
                padding: EdgeInsets.all(8.0),
                child: Text(
                  'Underline my parent!',
                  maxLines: 2,
                  textAlign: TextAlign.center,
                ),
              ),
            )
          ],
        ),
        decoration: Border(bottom: BorderSide(color: Colors.grey)),
      ),
Run Code Online (Sandbox Code Playgroud)

但是现在我希望下划线不是从头到尾,我希望在开始和结束时都有空间。如果有一些更聪明的方式来给小部件加下划线,我也会很高兴看到它。

Gra*_*Sim 12

BorderSide为您的容器添加底部。

     Container(
        decoration: BoxDecoration(
           border: Border(
              bottom: BorderSide(width: 1.0, color: Colors.black),
           ),
       ),
    ),
Run Code Online (Sandbox Code Playgroud)


Bos*_*rot 6

您可以使用Divider包含填充的简单小部件:

new Padding(
    padding: EdgeInsets.all(8.0), 
    child: new Divider()
),
Run Code Online (Sandbox Code Playgroud)

然后,您可以用一列包装现有的小部件:

new Column(
    children: <Widget> [
        yourContainerWidget,
        new Padding(
            padding: EdgeInsets.all(8.0), 
            child: new Divider()
        ),     
    ]
)
Run Code Online (Sandbox Code Playgroud)


小智 5

You can simply to create underline in Container widget using Border

here the code:

Container(
  padding: EdgeInsets.all(8.0),
  decoration: BoxDecoration(
    border: Border(
      bottom: BorderSide(
        width: 1.0
      ),
    ),
  ),
  child: Text(
    'Underline my parent!',
    maxLines: 2,
    textAlign: TextAlign.center,
  ),
), 
Run Code Online (Sandbox Code Playgroud)