DefaultButton.dart 2.1KB

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