Here is an expanded answer. A `DecoratedBox` is what you need to add a border, but I am using a `Container` for the convenience of adding margin and padding.
Here is the general setup.
[![enter image description here][1]][1]
Widget myWidget() {
return Container(
margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: myBoxDecoration(), // <--- BoxDecoration here
child: Text(
"text",
style: TextStyle(fontSize: 30.0),
),
);
}
where the `BoxDecoration` is
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(),
);
}
# Border width
[![enter image description here][2]][2]
These have a border width of `1`, `3`, and `10` respectively.
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(
width: 1, // <--- border width here
),
);
}
# Border color
[![enter image description here][3]][3]
These have a border color of
- `Colors.red`
- `Colors.blue`
- `Colors.green`
Code
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(
color: Colors.red, // <--- border color
width: 5.0,
),
);
}
# Border side
[![enter image description here][4]][4]
These have a border side of
- left (3.0), top (3.0)
- bottom (13.0)
- left (blue[100], 15.0), top (blue[300], 10.0), right (blue[500], 5.0), bottom (blue[800], 3.0)
Code
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border(
left: BorderSide( // <--- left side
color: Colors.black,
width: 3.0,
),
top: BorderSide( // <--- top side
color: Colors.black,
width: 3.0,
),
),
);
}
# Border radius
[![enter image description here][5]][5]
These have border radii of `5`, `10`, and `30` respectively.
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(
width: 3.0
),
borderRadius: BorderRadius.all(
Radius.circular(5.0) // <--- border radius here
),
);
}
# Going on
[`DecoratedBox`][6]/[`BoxDecoration`][7] are very flexible. Read [Flutter — BoxDecoration Cheat Sheet][8] for many more ideas.
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[To see links please register here]
[7]:
[To see links please register here]
[8]:
[To see links please register here]