rounded_button.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:flutter/material.dart';
  2. class RoundedTextButton extends StatelessWidget {
  3. final VoidCallback? press;
  4. final String? title;
  5. final double? width;
  6. final double? height;
  7. final BorderRadius borderRadius;
  8. final Color borderColor;
  9. final Color color;
  10. final Color textColor;
  11. final double fontSize;
  12. const RoundedTextButton({
  13. Key? key,
  14. this.press,
  15. this.title,
  16. this.width,
  17. this.height,
  18. this.borderRadius = BorderRadius.zero,
  19. this.borderColor = Colors.transparent,
  20. this.color = Colors.transparent,
  21. this.textColor = Colors.white,
  22. this.fontSize = 16,
  23. }) : super(key: key);
  24. @override
  25. Widget build(BuildContext context) {
  26. return ConstrainedBox(
  27. constraints: BoxConstraints(
  28. minWidth: 10,
  29. maxWidth: width ?? double.infinity,
  30. minHeight: 10,
  31. maxHeight: height ?? 60,
  32. ),
  33. child: Container(
  34. decoration: BoxDecoration(
  35. border: Border.all(color: borderColor),
  36. borderRadius: borderRadius,
  37. color: color,
  38. ),
  39. child: SizedBox.expand(
  40. child: TextButton(
  41. child: Text(
  42. title ?? '',
  43. style: TextStyle(color: textColor, fontSize: fontSize),
  44. ),
  45. onPressed: press,
  46. ),
  47. ),
  48. ),
  49. );
  50. }
  51. }
  52. class RoundedImageButton extends StatelessWidget {
  53. final VoidCallback? press;
  54. final double size;
  55. final BorderRadius borderRadius;
  56. final Color borderColor;
  57. final Color color;
  58. final Widget child;
  59. const RoundedImageButton({
  60. Key? key,
  61. this.press,
  62. required this.size,
  63. this.borderRadius = BorderRadius.zero,
  64. this.borderColor = Colors.transparent,
  65. this.color = Colors.transparent,
  66. required this.child,
  67. }) : super(key: key);
  68. @override
  69. Widget build(BuildContext context) {
  70. return SizedBox(
  71. width: size,
  72. height: size,
  73. child: TextButton(
  74. onPressed: press,
  75. style: ButtonStyle(
  76. shape: MaterialStateProperty.all<RoundedRectangleBorder>(
  77. RoundedRectangleBorder(
  78. borderRadius: borderRadius,
  79. ))),
  80. child: child,
  81. ),
  82. );
  83. }
  84. }