buildTextButton method
Implementation
Widget buildTextButton() {
if (isOutlined) {
return OutlinedButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
shadowColor: MaterialStateProperty.resolveWith(
(states) {
return Colors.transparent;
},
),
foregroundColor: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed)) {
//获取焦点和按下时的颜色
return pressedBackgroundColor;
}
//默认状态使用的颜色
return backgroundColor;
},
),
backgroundColor: MaterialStateProperty.resolveWith((states) {
//设置按下时的背景颜色
if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed)) {
return pressedBackgroundColor;
} else {
return backgroundColor;
}
}),
elevation: MaterialStateProperty.all(0),
side: MaterialStateProperty.all(BorderSide(color: borderColor)),
//设置按钮最小的大小
//minimumSize: MaterialStateProperty.all(size),
//外边框装饰
shape: MaterialStateProperty.all(outlinedBorder),
),
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: textColor,
fontSize: fontSize,
fontWeight: fontWeight,
),
),
onPressed: onClick,
);
} else {
return ElevatedButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
shadowColor: MaterialStateProperty.resolveWith(
(states) {
return Colors.transparent;
},
),
foregroundColor: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed)) {
//获取焦点和按下时的颜色
return pressedBackgroundColor;
}
//默认状态使用的颜色
return backgroundColor;
},
),
backgroundColor: MaterialStateProperty.resolveWith((states) {
//设置按下时的背景颜色
if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed)) {
return pressedBackgroundColor;
} else {
return backgroundColor;
}
}),
elevation: MaterialStateProperty.all(0),
//设置按钮的大小
minimumSize: MaterialStateProperty.all(size),
//外边框装饰
shape: MaterialStateProperty.all(outlinedBorder),
),
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: textColor,
fontSize: fontSize,
fontWeight: fontWeight,
),
),
onPressed: onClick,
);
}
}