DefaultButton.dart 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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,fontSize,backColor,color,radius);
  31. }
  32. return _DefaultButtonState(onPressed, text, margin,width,height,fontSize,backColor,color,radius);
  33. }
  34. }
  35. class _DefaultButtonState extends State<DefaultButton> {
  36. //点击回调
  37. final GestureTapCallback onPressed;
  38. final String text;
  39. final EdgeInsetsGeometry margin;
  40. final double width;
  41. final double height;
  42. final double? fontSize;
  43. final Color backColor;
  44. final Color color;
  45. final double? radius;
  46. _DefaultButtonState(
  47. this.onPressed,
  48. this.text,
  49. this.margin,
  50. this.width,
  51. this.height,
  52. this.fontSize,
  53. this.backColor,
  54. this.color,
  55. this.radius
  56. );
  57. @override
  58. Widget build(BuildContext context) {
  59. Widget _SectionBtn = Container(
  60. margin: margin,
  61. child: SizedBox(
  62. width: width,
  63. height: height,
  64. child: RaisedButton(
  65. color: backColor,
  66. disabledColor: const Color(0xF5F6F7ff),
  67. disabledTextColor: const Color(0xF5F6F7ff),
  68. colorBrightness: Brightness.dark,
  69. shape:
  70. RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius??5)),
  71. child: Text(text,style: TextStyle(
  72. fontSize: fontSize,
  73. fontWeight: FontWeight.bold,
  74. color: color,
  75. ),),
  76. textColor: Colors.white,
  77. onPressed: onPressed,
  78. ),
  79. ),
  80. );
  81. return _SectionBtn;
  82. }
  83. }