DefaultButton.dart 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'package:flutter/material.dart';
  2. class DefaultButton extends StatefulWidget {
  3. //点击回调
  4. final GestureTapCallback onPressed;
  5. final String text;
  6. final EdgeInsetsGeometry margin;
  7. final double width;
  8. final double height;
  9. final double? fontSize;
  10. final Color backColor;
  11. final Color color;
  12. final double? radius;
  13. EdgeInsetsGeometry marginDefault =
  14. const EdgeInsets.fromLTRB(0, 90.0, 0, 30); //按钮默认的margin值
  15. DefaultButton({
  16. Key? key,
  17. required this.onPressed,
  18. required this.text,
  19. required this.margin,
  20. required this.width,
  21. required this.height,
  22. this.fontSize,
  23. this.radius,
  24. required this.backColor,
  25. required this.color,
  26. }) : super(key: key);
  27. @override
  28. State createState() {
  29. if (margin == null) {
  30. return _DefaultButtonState(onPressed, text, marginDefault, width, height,
  31. fontSize, backColor, color, radius);
  32. }
  33. return _DefaultButtonState(onPressed, text, margin, width, height, fontSize,
  34. backColor, color, radius);
  35. }
  36. }
  37. class _DefaultButtonState extends State<DefaultButton> {
  38. //点击回调
  39. final GestureTapCallback onPressed;
  40. final String text;
  41. final EdgeInsetsGeometry margin;
  42. final double width;
  43. final double height;
  44. final double? fontSize;
  45. final Color backColor;
  46. final Color color;
  47. final double? radius;
  48. _DefaultButtonState(this.onPressed, this.text, this.margin, this.width,
  49. this.height, this.fontSize, this.backColor, this.color, this.radius);
  50. @override
  51. Widget build(BuildContext context) {
  52. Widget _SectionBtn = Container(
  53. margin: margin,
  54. child: SizedBox(
  55. width: width,
  56. height: height,
  57. child: RaisedButton(
  58. color: backColor,
  59. disabledColor: const Color(0xF5F6F7ff),
  60. disabledTextColor: const Color(0xF5F6F7ff),
  61. colorBrightness: Brightness.dark,
  62. shape: RoundedRectangleBorder(
  63. borderRadius: BorderRadius.circular(radius ?? 5)),
  64. child: Text(
  65. text,
  66. style: TextStyle(
  67. fontSize: fontSize,
  68. fontWeight: FontWeight.bold,
  69. color: color,
  70. ),
  71. ),
  72. textColor: Colors.white,
  73. onPressed: onPressed,
  74. ),
  75. ),
  76. );
  77. return _SectionBtn;
  78. }
  79. }