main_button.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. const MainButton(
  10. {super.key,
  11. required this.text,
  12. required this.onPressed,
  13. this.buttonPadding,
  14. this.isOutlined = false});
  15. @override
  16. Widget build(BuildContext context) {
  17. return isOutlined
  18. ? OutlinedButton(
  19. onPressed: onPressed,
  20. style: ButtonStyle(
  21. padding: buttonPadding == null
  22. ? null
  23. : WidgetStatePropertyAll(buttonPadding),
  24. side: WidgetStatePropertyAll(
  25. BorderSide(color: Color(0xFFD2D2D2)))),
  26. child: Text(
  27. text,
  28. style: TextStyle(color: context.onSurfaceColor),
  29. ))
  30. : ElevatedButton(
  31. onPressed: onPressed,
  32. style: ButtonStyle(
  33. padding: buttonPadding == null
  34. ? null
  35. : WidgetStatePropertyAll(buttonPadding),
  36. backgroundColor: WidgetStatePropertyAll(context.primaryColor),
  37. elevation: const WidgetStatePropertyAll(0.0)),
  38. child: Text(
  39. text,
  40. textAlign: TextAlign.center,
  41. style: TextStyle(
  42. color: context.onPrimaryColor, fontWeight: FontWeight.bold),
  43. ));
  44. }
  45. }