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

问题描述 投票:1回答:2
        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装饰添加边框,但是当我尝试在内部容器上执行相同操作时,这使我出错。问题出在哪里,如何解决?

flutter layout widget border flutter-layout
2个回答
0
投票
这应该起作用:

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


0
投票
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, )), ) ], ), ),
© www.soinside.com 2019 - 2024. All rights reserved.