flutter - 如何在 Flutter 中的行小部件内的容器上添加边框?

标签 flutter layout widget border flutter-layout

        Container(
    //            decoration: BoxDecoration(
    //              border: Border.all(color: Colors.black45),
    //              borderRadius: BorderRadius.circular(8.0),
    //            ),
                child: Row(
                  children: <Widget>[
                    Container(
                      child: Text("hi"),
                      margin : EdgeInsets.fromLTRB(20, 8, 8, 16),
                      width: MediaQuery.of(context).size.width *0.42,
                      height: 90,
                      color: Colors.black12,
                    ),

                    Container(
                      child: Text("Hi"),
                      margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
                      width: MediaQuery.of(context).size.width * 0.42 ,
                      height: 90,
                      color: Colors.black12,
                    )
                  ],
                ),
              ),

我可以在外部容器上使用 Box 装饰添加边框,但是当我尝试在内部容器上执行相同操作时,它会引发错误。问题是什么以及如何解决?

最佳答案

为了在行小部件内的容器上添加边框,我们必须对内部容器使用装饰。
一旦您发布错误,我们可以更好地回答您,但我认为以下代码将对您有所帮助。
如果你使用的是装饰,那么你不能直接在容器中添加颜色属性,它应该只是在装饰中。

     Container(
          child: Row(
            children: <Widget>[
              Container(
                child: Text("hi"),
                margin: EdgeInsets.fromLTRB(20, 8, 8, 16),
                width: MediaQuery.of(context).size.width * 0.42,
                height: 90,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(4)),
                    shape: BoxShape.rectangle,
                    border: Border.all(
                      color: Colors.blue,
                      width: 4,
                    )),
              ),
              Container(
                child: Text("Hi"),
                margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
                width: MediaQuery.of(context).size.width * 0.42,
                height: 90,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(4)),
                    shape: BoxShape.rectangle,
                    border: Border.all(
                      color: Colors.blue,
                      width: 4,
                    )),
              )
            ],
          ),
        ),

关于flutter - 如何在 Flutter 中的行小部件内的容器上添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60830260/

相关文章:

flutter - Firestore集合快照不会转换为CSV

css - 带有页眉和页脚的 100% Css 布局

java - 如何设置 SashForm 子项默认大小

html - 如何使同级div动态填充父级?

css - 页面加载时将 div 设置为 100% View 端口大小

flutter - 如何制作可重用的 Futurebuilder

python - Jupyter notebook 上的多个依赖小部件(下拉菜单)

flutter : Custom Painter draw path with different fill and stroke color

Flutter - 显示来自本地 json 文件的图像 url

Flutter - 如何从 BottomNavigationBar 中删除填充?