import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ftrecruiter/comm/constants/color_constants.dart'; import 'package:ftrecruiter/comm/utils/dark_theme_util.dart'; /// 默认字号18,白字蓝底,高度48 class MyButton extends StatelessWidget { const MyButton({ Key? key, this.text = '', this.fontSize = 16, this.textColor, this.disabledTextColor, this.backgroundColor, this.disabledBackgroundColor, this.minHeight = 48.0, this.minWidth = double.infinity, this.padding = const EdgeInsets.symmetric(horizontal: 16.0), this.radius = 5.0, this.side = BorderSide.none, required this.onPressed, }) : super(key: key); final String text; final double fontSize; final Color? textColor; final Color? disabledTextColor; final Color? backgroundColor; final Color? disabledBackgroundColor; final double? minHeight; final double? minWidth; final VoidCallback? onPressed; final EdgeInsetsGeometry padding; final double radius; final BorderSide side; @override Widget build(BuildContext context) { return TextButton( onPressed: onPressed, style: ButtonStyle( // 文字颜色 foregroundColor: MaterialStateProperty.resolveWith( (states) { if (states.contains(MaterialState.disabled)) { return DarkThemeUtil.multiColors(disabledTextColor ?? Colors.grey, darkColor: Colors.grey); } return DarkThemeUtil.multiColors(textColor ?? Colors.white,darkColor: Colors.white); }, ), // 背景颜色 backgroundColor: MaterialStateProperty.resolveWith((states) { if (states.contains(MaterialState.disabled)) { return DarkThemeUtil.multiColors(disabledBackgroundColor ?? Colors.white,darkColor: Colors.lightBlue); } return DarkThemeUtil.multiColors(backgroundColor ?? Colors.white,darkColor: ColorConstants.appBlue); }), // 水波纹 overlayColor: MaterialStateProperty.resolveWith((states) { return DarkThemeUtil.multiColors(textColor ?? Colors.white).withOpacity(0.12); }), // 按钮最小大小 minimumSize: (minWidth == null || minHeight == null) ? null : MaterialStateProperty.all(Size(minWidth!, minHeight!)), padding: MaterialStateProperty.all(padding), shape: MaterialStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(radius), ), ), side: MaterialStateProperty.all(side), ), child: Text( text, style: TextStyle(fontSize: fontSize), )); } }