简介
ShapeBorder 用于设置形状和轮廓,比如圆形,矩形,圆角矩形等。常用于 Container 中。
继承结构如下:
- ShapeBorder【abstract】
- BeveledRectangleBorder
- BoxBorder【abstract】
- Border
- BorderDirectional
- CircleBorder
- ContinuousRectangleBorder
- RoundedRectangleBorder
- StadiumBorder
- InputBorder【abstract】
- OutlineInputBorder
- UnderlineInputBorder
其中 ShapeBorder、BoxBorder、InputBorder 是抽象父类。InputBorder 通常用于输入框相关的。
类的关系图
![ShapeBorder 子类继承关系图](/images/flutter_shape_border/ShapeBorder 子类继承关系图.png)
BeveledRectangleBorder
斜面圆角矩形
继承关系:
BeveledRectangleBorder > ShapeBorder
```dart
Widget _beveledRectangleBorder() {
return Center(
child: Container(
width: 240,
height: 120,
margin: EdgeInsets.all(16),
decoration: ShapeDecoration(
image: DecorationImage(
image: AssetImage(‘lib/assets/img_flutter.png’),
fit: BoxFit.cover,
),
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(20),
side: BorderSide(
width: 2,
color: Colors.blue,
style: BorderStyle.solid,
),
),
),
),
);
}
1 |
|
效果图:
BorderDirectional
继承关系:
BorderDirectional > BoxBorder > ShapeBorder
BorderDirectional
通过 top
, bottom
, start
, end
分别控制上下左右的边线
边线对象 BorderSide
```dart
Widget _borderDirectional() {
return Center(
child: Container(
width: 240,
height: 120,
margin: EdgeInsets.all(16),
decoration: ShapeDecoration(
image: DecorationImage(
image: AssetImage(‘lib/assets/img_flutter.png’),
fit: BoxFit.cover,
),
shape: BorderDirectional(
start: BorderSide(color: Colors.black, width: 15),
end: BorderSide(color: Colors.black, width: 15),
top: BorderSide(
color: Colors.black,
),
bottom: BorderSide(
color: Colors.black,
),
),
),
),
);
}
1 |
|
效果如下:
CircleBorder
圆形边框。
继承关系:
CircleBorder > ShapeBorder
```dart
Widget _circleBorder1() {
return Center(
child: Container(
width: 120,
height: 120,
margin: EdgeInsets.all(16),
decoration: ShapeDecoration(
image: DecorationImage(
image: AssetImage(‘lib/assets/img_flutter.png’),
fit: BoxFit.cover,
),
shape: CircleBorder(
side: BorderSide(),
),
),
),
);
}
1 |
|
效果如下:
ContinuousRectangleBorder
平滑过渡的矩形边框
继承关系:
ContinuousRectangleBorder > ShapeBorder
```dart
Widget _continuousRectangleBorder() {
return Center(
child: Container(
width: 240,
height: 120,
margin: EdgeInsets.all(16),
decoration: ShapeDecoration(
image: DecorationImage(
image: AssetImage(‘lib/assets/img_flutter.png’),
fit: BoxFit.cover,
),
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.circular(40),
side: BorderSide(
width: 2,
color: Colors.blue,
style: BorderStyle.solid,
),
),
),
),
);
}
1 |
|
效果如下:
StadiumBorder
体育场形状。即两边是半圆。
继承关系:
StadiumBorder > ShapeBorder
```dart
Widget _stadiumBorder() {
return Center(
child: Container(
width: 240,
height: 120,
margin: EdgeInsets.all(16),
decoration: ShapeDecoration(
image: DecorationImage(
image: AssetImage(‘lib/assets/img_flutter.png’),
fit: BoxFit.cover,
),
shape: StadiumBorder(
side: BorderSide(
width: 2,
color: Colors.blue,
style: BorderStyle.solid,
),
),
),
),
);
}
1 |
|
效果如下:
UnderlineInputBorder
继承关系:
UnderlineInputBorder > InputBorder > ShapeBorder
```dart
Widget _underlineInputBorder() {
return Center(
child: Container(
margin: EdgeInsets.all(16),
padding: EdgeInsets.all(16),
decoration: ShapeDecoration(
color: Colors.orange,
shape: UnderlineInputBorder(
borderSide: BorderSide(width: 2.0, color: Colors.purple),
borderRadius: BorderRadius.circular(20.0),
),
),
child: Text(
“UnderlineInputBorder”,
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
);
}
效果如下:
![underlineInput_border](/images/flutter_shape_border/underlineInput_border.png)
<!-- processed 2 -->