How to add a border to a widget in Flutter?

后端 未结 7 629
别那么骄傲
别那么骄傲 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:23

    As stated in the documentation, flutter prefer composition over parameters. Most of the time what you're looking for is not a property, but instead a wrapper (and sometimes a few helpers/"builder")

    For borders what you want is DecoratedBox, which has a decoration property that defines borders ; but also background images or shadows.

    Alternatively like @Aziza said, you can use Container. Which is the combination of DecoratedBox, SizedBox and a few other useful widgets.

提交回复
热议问题