How to add a border to a widget in Flutter?

后端 未结 7 630
别那么骄傲
别那么骄傲 2020-11-30 18:38

I\'m using Flutter and I\'d like to add a border to a widget (in this case, a Text widget).

I tried TextStyle and Text, but I didn\'t see how to add a border.

7条回答
  •  暖寄归人
    2020-11-30 19:22

    Best way is using BoxDecoration()

    Advantage

    • You can set border of widget
    • You can set border Color or Width
    • You can set Rounded corner of border
    • You can add Shadow of widget

    Disadvantage

    • BoxDecoration only use with Container widget so you want to wrap your widget in Container()

    Example

        Container(
          margin: EdgeInsets.all(10),
          padding: EdgeInsets.all(10),
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Colors.orange,
            border: Border.all(
                color: Colors.pink[800],// set border color
                width: 3.0),   // set border width
            borderRadius: BorderRadius.all(
                Radius.circular(10.0)), // set rounded corner radius
            boxShadow: [BoxShadow(blurRadius: 10,color: Colors.black,offset: Offset(1,3))]// make rounded corner of border
          ),
          child: Text("My demo styling"),
        )
    

提交回复
热议问题