main_button.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'package:flutter/material.dart';
  2. ///主要按钮
  3. class MainButton extends StatelessWidget {
  4. final void Function() onPressed;
  5. final String text;
  6. final bool isOutlined;
  7. final EdgeInsets? buttonPadding;
  8. const MainButton(
  9. {super.key,
  10. required this.text,
  11. required this.onPressed,
  12. this.buttonPadding,
  13. this.isOutlined = false});
  14. @override
  15. Widget build(BuildContext context) {
  16. return isOutlined
  17. ? OutlinedButton(
  18. onPressed: onPressed,
  19. style: ButtonStyle(
  20. padding: buttonPadding == null
  21. ? null
  22. : WidgetStatePropertyAll(buttonPadding),
  23. side: WidgetStatePropertyAll(
  24. BorderSide(color: Color(0xFFD2D2D2)))),
  25. child: Text(
  26. text,
  27. style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
  28. ))
  29. : ElevatedButton(
  30. onPressed: onPressed,
  31. style: ButtonStyle(
  32. padding: buttonPadding == null
  33. ? null
  34. : WidgetStatePropertyAll(buttonPadding),
  35. backgroundColor:
  36. WidgetStatePropertyAll(Theme.of(context).primaryColor),
  37. elevation: const WidgetStatePropertyAll(0.0)),
  38. child: Text(
  39. text,
  40. textAlign: TextAlign.center,
  41. style: TextStyle(
  42. color: Theme.of(context).colorScheme.onPrimary,
  43. fontWeight: FontWeight.bold),
  44. ));
  45. }
  46. }