my_button.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:ftrecruiter/comm/constants/color_constants.dart';
  4. import 'package:ftrecruiter/comm/utils/dark_theme_util.dart';
  5. /// 默认字号18,白字蓝底,高度48
  6. class MyButton extends StatelessWidget {
  7. const MyButton({
  8. Key? key,
  9. this.text = '',
  10. this.fontSize = 16,
  11. this.textColor,
  12. this.disabledTextColor,
  13. this.backgroundColor,
  14. this.disabledBackgroundColor,
  15. this.minHeight = 48.0,
  16. this.minWidth = double.infinity,
  17. this.padding = const EdgeInsets.symmetric(horizontal: 16.0),
  18. this.radius = 5.0,
  19. this.side = BorderSide.none,
  20. required this.onPressed,
  21. }) : super(key: key);
  22. final String text;
  23. final double fontSize;
  24. final Color? textColor;
  25. final Color? disabledTextColor;
  26. final Color? backgroundColor;
  27. final Color? disabledBackgroundColor;
  28. final double? minHeight;
  29. final double? minWidth;
  30. final VoidCallback? onPressed;
  31. final EdgeInsetsGeometry padding;
  32. final double radius;
  33. final BorderSide side;
  34. @override
  35. Widget build(BuildContext context) {
  36. return TextButton(
  37. onPressed: onPressed,
  38. style: ButtonStyle(
  39. // 文字颜色
  40. foregroundColor: MaterialStateProperty.resolveWith(
  41. (states) {
  42. if (states.contains(MaterialState.disabled)) {
  43. return DarkThemeUtil.multiColors(disabledTextColor ?? Colors.grey, darkColor: Colors.grey);
  44. }
  45. return DarkThemeUtil.multiColors(textColor ?? Colors.white,darkColor: Colors.white);
  46. },
  47. ),
  48. // 背景颜色
  49. backgroundColor: MaterialStateProperty.resolveWith((states) {
  50. if (states.contains(MaterialState.disabled)) {
  51. return DarkThemeUtil.multiColors(disabledBackgroundColor ?? Colors.white,darkColor: Colors.lightBlue);
  52. }
  53. return DarkThemeUtil.multiColors(backgroundColor ?? Colors.white,darkColor: ColorConstants.appBlue);
  54. }),
  55. // 水波纹
  56. overlayColor: MaterialStateProperty.resolveWith((states) {
  57. return DarkThemeUtil.multiColors(textColor ?? Colors.white).withOpacity(0.12);
  58. }),
  59. // 按钮最小大小
  60. minimumSize: (minWidth == null || minHeight == null)
  61. ? null
  62. : MaterialStateProperty.all<Size>(Size(minWidth!, minHeight!)),
  63. padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding),
  64. shape: MaterialStateProperty.all<OutlinedBorder>(
  65. RoundedRectangleBorder(
  66. borderRadius: BorderRadius.circular(radius),
  67. ),
  68. ),
  69. side: MaterialStateProperty.all<BorderSide>(side),
  70. ),
  71. child: Text(
  72. text,
  73. style: TextStyle(fontSize: fontSize),
  74. ));
  75. }
  76. }