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 Colors.transparent;
},
),
backgroundColor: MaterialStateProperty.resolveWith((states) {
//设置按下时的背景颜色
if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed)) {
return pressedBackgroundColor;
} else {
return Colors.transparent;
}
}),
elevation: MaterialStateProperty.all(0),
side: MaterialStateProperty.all(BorderSide(color: borderColor)),
//设置按钮最小的大小
maximumSize:MaterialStateProperty.all(size),
minimumSize: MaterialStateProperty.all(size),
//外边框装饰
shape: MaterialStateProperty.all(outlinedBorder),
),
child: Container(
width: this.size.width,
height: this.size.height,
padding: EdgeInsets.only(top: 0, left: 1, right: 1, bottom: 0),
child: Row(mainAxisAlignment: mainAxisAlignment, crossAxisAlignment: CrossAxisAlignment.center, children: [
this.iconLeft.isNotEmpty
? Image.asset(
this.iconLeft,
fit: BoxFit.fitHeight,
height: this.size.height * 0.6,
)
: Container(),
Padding(
padding: EdgeInsets.only(top: 0, left: 5, right: 5, bottom: 0),
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: textColor,
fontSize: fontSize,
fontWeight: fontWeight,
),
),
),
this.iconRight.isNotEmpty
? Image.asset(
iconRight,
fit: BoxFit.fitHeight,
height: this.size.height * 0.6,
)
: Container(),
]),
),
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),
//设置按钮最小的大小
maximumSize:MaterialStateProperty.all(size),
minimumSize: MaterialStateProperty.all(size),
//外边框装饰
shape: MaterialStateProperty.all(outlinedBorder),
),
child: Container(
width: this.size.width,
height: this.size.height,
padding: EdgeInsets.only(top: 0, left: 1, right: 1, bottom: 0),
child: Row(mainAxisAlignment: mainAxisAlignment, crossAxisAlignment: CrossAxisAlignment.center, children: [
this.iconLeft.isNotEmpty
? Image.asset(
this.iconLeft,
fit: BoxFit.fitHeight,
height: this.size.height * 0.6,
)
: Container(),
Padding(
padding: EdgeInsets.only(top: 0, left: 5, right: 5, bottom: 0),
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: textColor,
fontSize: fontSize,
fontWeight: fontWeight,
),
),
),
this.iconRight.isNotEmpty
? Image.asset(
iconRight,
fit: BoxFit.fitHeight,
height: this.size.height * 0.6,
)
: Container(),
]),
),
onPressed: () {
onClick();
},
);
}
}