button.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'package:fast/extension/layout.dart';
  2. import 'package:flutter/material.dart';
  3. class RRectButton extends StatelessWidget {
  4. const RRectButton(
  5. this.text, {
  6. Key? key,
  7. this.width = 64,
  8. this.height = 32,
  9. this.radius = 12,
  10. this.textColor,
  11. this.fontSize,
  12. this.backgroundColor = Colors.transparent,
  13. this.gradientColors = const [Colors.transparent, Colors.transparent],
  14. this.onPressed,
  15. }) : super(key: key);
  16. final String text;
  17. final double width;
  18. final double height;
  19. final Color? textColor;
  20. final double? fontSize;
  21. final Color? backgroundColor;
  22. final List<Color>? gradientColors;
  23. final double radius;
  24. final VoidCallback? onPressed;
  25. @override
  26. Widget build(BuildContext context) {
  27. return SizedBox(
  28. width: width,
  29. height: height,
  30. child: Container(
  31. padding: EdgeInsets.zero,
  32. margin: EdgeInsets.zero,
  33. decoration: BoxDecoration(
  34. gradient: gradientColors
  35. ?.let((it) => LinearGradient(colors: gradientColors!)),
  36. borderRadius: BorderRadius.circular(radius),
  37. ),
  38. child: ElevatedButton(
  39. onPressed: onPressed,
  40. child: Text(
  41. text,
  42. style: textColor
  43. ?.let((it) => TextStyle(color: textColor, fontSize: fontSize)),
  44. ),
  45. style: ButtonStyle(
  46. padding: MaterialStateProperty.all(EdgeInsets.zero),
  47. // tapTargetSize: MaterialTapTargetSize.shrinkWrap,
  48. shape: MaterialStateProperty.all(RoundedRectangleBorder(
  49. borderRadius: BorderRadius.circular(radius))),
  50. backgroundColor: MaterialStateProperty.all(backgroundColor),
  51. ),
  52. ),
  53. ),
  54. );
  55. }
  56. }
  57. class RRectOutlinedButton extends StatelessWidget {
  58. const RRectOutlinedButton(
  59. this.text, {
  60. Key? key,
  61. this.width = 64,
  62. this.height = 32,
  63. this.radius = 12,
  64. this.textColor,
  65. this.fontSize,
  66. this.backgroundColor = Colors.transparent,
  67. this.gradientColors,
  68. this.onPressed,
  69. }) : super(key: key);
  70. final String text;
  71. final double width;
  72. final double height;
  73. final Color? textColor;
  74. final double? fontSize;
  75. final Color? backgroundColor;
  76. final List<Color>? gradientColors;
  77. final double radius;
  78. final VoidCallback? onPressed;
  79. @override
  80. Widget build(BuildContext context) {
  81. return SizedBox(
  82. width: width,
  83. height: height,
  84. child: Container(
  85. padding: EdgeInsets.zero,
  86. margin: EdgeInsets.zero,
  87. decoration: BoxDecoration(
  88. gradient: gradientColors
  89. ?.let((it) => LinearGradient(colors: gradientColors!)),
  90. borderRadius: BorderRadius.circular(radius),
  91. ),
  92. child: OutlinedButton(
  93. onPressed: onPressed,
  94. child: Text(
  95. text,
  96. style: TextStyle(color: textColor, fontSize: fontSize),
  97. ),
  98. style: OutlinedButton.styleFrom(
  99. padding: EdgeInsets.zero,
  100. // tapTargetSize: MaterialTapTargetSize.shrinkWrap,
  101. shape: RoundedRectangleBorder(
  102. borderRadius: BorderRadius.circular(radius),
  103. ),
  104. side: const BorderSide(color: Colors.blue, style: BorderStyle.solid),
  105. backgroundColor: backgroundColor,
  106. ),
  107. ),
  108. ),
  109. );
  110. }
  111. }