使用方法:他们的使用方法都一样
1、 TextButton:
效果:
2、 OutlinedButton:
效果:
3、ElevatedButton
效果:
属性API:
1、点击事件 onPressed
2、长按事件 onLongPress
3、属性:
textStyle 字体
backgroundColor 背景颜色
foregroundColor 字体颜色
overlayColor 高亮色,按钮处于focused, hovered, or pressed时的颜色
side 边框
shadowColor 阴影颜色
elevation 阴影值
shape 形状-可设置圆角弧度
TextButton(
child: Text("爱你"),
onPressed: () {},
);
OutlinedButton(
child: Text("爱你"),
onPressed: () {},
);
ElevatedButton(
child: Text("爱你"),
onPressed: () {},
);
ElevatedButton(
child: Text("爱你"),
onPressed: () {
print('我被点击了');
},
);
ElevatedButton(
child: Text("爱你"),
onLongPress : () {
print('我被长按了');
},
);
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
textStyle: MaterialStateProperty.all(TextStyle(fontSize: 16)), //字体
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Color(0xffEDFCF5)), //背景颜色
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(Color(0xff31C27C)), //字体颜色
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Color(0xff31C27C)), //字体颜色
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
side: MaterialStateProperty.all(BorderSide(width: 1,color: Color(0xffffffff))),//边框
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
shadowColor: MaterialStateProperty.all(Colors.red),
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("爱你"),
style: ButtonStyle(
elevation: MaterialStateProperty.all(10), //阴影值
),
onPressed: () {
print('我被点击了');
},
)
(1)棱形,如果不设置边框,可以实现圆角弧度那种效果,设置边框就是棱形
ElevatedButton(
child: Text("审核完成"),
style: ButtonStyle(
side: MaterialStateProperty.all(BorderSide(width: 1,color: Color(0xffCAD0DB))),//边框
shape: MaterialStateProperty.all(BeveledRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
),
onPressed: () {
print('我被点击了');
},
)
ElevatedButton(
child: Text("学习报告"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Color(0xffFFF8E5)), //背景颜色
foregroundColor: MaterialStateProperty.all(Color(0xffB85F23)), //字体颜色
overlayColor: MaterialStateProperty.all(Color(0xffFFF8E5)), // 高亮色
shadowColor: MaterialStateProperty.all( Color(0xffffffff)), //阴影颜色
elevation: MaterialStateProperty.all(0), //阴影值
textStyle: MaterialStateProperty.all(TextStyle(fontSize: 12)), //字体
side: MaterialStateProperty.all(BorderSide(width: 1,color: Color(0xffffffff))),//边框
shape: MaterialStateProperty.all(BeveledRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
),
onPressed: () {},
);
(2)圆形
ElevatedButton(
child: Text("审"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Color(0xffffffff)), //背景颜色
foregroundColor: MaterialStateProperty.all(Color(0xff5E6573)), //字体颜色
overlayColor: MaterialStateProperty.all(Color(0xffffffff)), // 高亮色
shadowColor: MaterialStateProperty.all( Color(0xffffffff)), //阴影颜色
elevation: MaterialStateProperty.all(0), //阴影值
textStyle: MaterialStateProperty.all(TextStyle(fontSize: 12)), //字体
side: MaterialStateProperty.all(BorderSide(width: 1,color: Color(0xffCAD0DB))),//边框
shape: MaterialStateProperty.all(
CircleBorder(
side: BorderSide(
//设置 界面效果
color: Colors.green,
width: 280.0,
style: BorderStyle.none,
)
)
),//圆角弧度
),
onPressed: () {},
)
(3)圆角弧度 (这个直接就是)
ElevatedButton(
child: Text("审核完成"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Color(0xffffffff)), //背景颜色
foregroundColor: MaterialStateProperty.all(Color(0xff5E6573)), //字体颜色
overlayColor: MaterialStateProperty.all(Color(0xffffffff)), // 高亮色
shadowColor: MaterialStateProperty.all( Color(0xffffffff)), //阴影颜色
elevation: MaterialStateProperty.all(0), //阴影值
textStyle: MaterialStateProperty.all(TextStyle(fontSize: 12)), //字体
side: MaterialStateProperty.all(BorderSide(width: 1,color: Color(0xffCAD0DB))),//边框
shape: MaterialStateProperty.all(
StadiumBorder(
side: BorderSide(
//设置 界面效果
style: BorderStyle.solid,
color: Color(0xffFF7F24),
)
)
),//圆角弧度
),