flutter-button小组件
Widget btnFlatButtonWidget({
required VoidCallback onPressed,
Widget? text,
double width = 140,
double height = 44,
Color gbColor = AppColors.primaryElement,
String title = "button",
Color fontColor = AppColors.primaryElementText,
Color borderColor = AppColors.secondaryElementText,
double fontSize = 16,
double borderRadius=8,
double borderwidth = 1,
String fontName = "Montserrat",
FontWeight fontWeight = FontWeight.w400,
}) {
return Container(
width: width.w,
height: height.h,
child: TextButton(
style: ButtonStyle(
textStyle: MaterialStateProperty.all(TextStyle(
fontSize: 16.sp,
)),
foregroundColor: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.focused) &&
!states.contains(MaterialState.pressed)) {
return Colors.blue;
} else if (states.contains(MaterialState.pressed)) {
return Colors.deepPurple;
}
return fontColor;
},
),
backgroundColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.pressed)) {
return Colors.blue[200];
}
return gbColor;
}),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
side: BorderSide(width: borderwidth, color: borderColor),
borderRadius: BorderRadius.circular(borderRadius),
)
),
),
child: Text(
title,
textAlign: TextAlign.center,
style: TextStyle(
color: fontColor,
fontFamily: fontName,
fontWeight: fontWeight,
fontSize: fontSize,
height: 1,
),
),
onPressed: onPressed,
),
);
}
颜色记录
蓝色
Theme.of(context).colorScheme.primary
黑色
Theme.of(context).colorScheme.onSurface