rounded_button.dart 2.1 KB

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