main_button.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:eitc_erm_dental_flutter/exts.dart';
  2. import 'package:flutter/material.dart';
  3. ///主要按钮
  4. class MainButton extends StatelessWidget {
  5. final void Function() onPressed;
  6. final String text;
  7. final bool isOutlined;
  8. final EdgeInsets? buttonPadding;
  9. final Size? minimumSize;
  10. final Size? maximumSize;
  11. final bool fitMinimumSize;
  12. final OutlinedBorder? shape;
  13. const MainButton(
  14. {super.key,
  15. required this.text,
  16. required this.onPressed,
  17. this.buttonPadding,
  18. this.minimumSize,
  19. this.maximumSize,
  20. this.isOutlined = false,
  21. this.fitMinimumSize = false,
  22. this.shape});
  23. @override
  24. Widget build(BuildContext context) {
  25. return isOutlined
  26. ? OutlinedButton(
  27. onPressed: onPressed,
  28. style: ButtonStyle(
  29. tapTargetSize:
  30. fitMinimumSize ? MaterialTapTargetSize.shrinkWrap : null,
  31. padding: buttonPadding == null
  32. ? null
  33. : WidgetStatePropertyAll(buttonPadding),
  34. minimumSize: minimumSize == null
  35. ? null
  36. : WidgetStatePropertyAll(minimumSize),
  37. maximumSize: maximumSize == null
  38. ? null
  39. : WidgetStatePropertyAll(maximumSize),
  40. side: WidgetStatePropertyAll(
  41. BorderSide(color: Color(0xFFD2D2D2))),
  42. shape: shape == null ? null : WidgetStatePropertyAll(shape)),
  43. child: Text(
  44. text,
  45. style: TextStyle(color: context.onSurfaceColor),
  46. ))
  47. : ElevatedButton(
  48. onPressed: onPressed,
  49. style: ButtonStyle(
  50. tapTargetSize:
  51. fitMinimumSize ? MaterialTapTargetSize.shrinkWrap : null,
  52. padding: buttonPadding == null
  53. ? null
  54. : WidgetStatePropertyAll(buttonPadding),
  55. backgroundColor: WidgetStatePropertyAll(context.primaryColor),
  56. minimumSize: minimumSize == null
  57. ? null
  58. : WidgetStatePropertyAll(minimumSize),
  59. maximumSize: maximumSize == null
  60. ? null
  61. : WidgetStatePropertyAll(maximumSize),
  62. elevation: const WidgetStatePropertyAll(0.0),
  63. shape: shape == null ? null : WidgetStatePropertyAll(shape)),
  64. child: Text(
  65. text,
  66. textAlign: TextAlign.center,
  67. style: TextStyle(
  68. color: context.onPrimaryColor, fontWeight: FontWeight.bold),
  69. ));
  70. }
  71. }