imageButton.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import 'package:flutter/material.dart';
  2. class ImageButton extends StatelessWidget {
  3. final Size buttonSize;
  4. final String image;
  5. final Size imageSize;
  6. final Color bgColor;
  7. final double borderRadius;
  8. final Color borderColor;
  9. final double borderWidth;
  10. final VoidCallback? onTap;
  11. ImageButton({
  12. required this.buttonSize,
  13. required this.image,
  14. Size? imageSize,
  15. this.bgColor = Colors.white,
  16. this.borderRadius = 5,
  17. Color? borderColor,
  18. this.borderWidth = 1,
  19. this.onTap,
  20. })
  21. : imageSize = imageSize ?? buttonSize,
  22. borderColor = borderColor ?? bgColor
  23. ;
  24. @override
  25. Widget build(BuildContext context) {
  26. return GestureDetector(
  27. onTap: onTap,
  28. child: Opacity(
  29. opacity: onTap == null ? 0.5 : 1.0,
  30. child: Container(
  31. width: buttonSize.width,
  32. height: buttonSize.height,
  33. decoration: BoxDecoration(
  34. color: bgColor,
  35. shape: BoxShape.rectangle,
  36. borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
  37. border: Border.all(color: borderColor),
  38. ),
  39. child: Center(
  40. child: Image.asset(
  41. image,
  42. width: imageSize.width,
  43. height: imageSize.height,
  44. ),
  45. ),
  46. ),
  47. ),
  48. );
  49. }
  50. }
  51. class ImageColumnTextButton extends StatelessWidget {
  52. final Size buttonSize;
  53. final String image;
  54. final Size imageSize;
  55. final String text;
  56. final TextStyle? textStyle;
  57. final double space;
  58. final Color bgColor;
  59. final double borderRadius;
  60. final Color borderColor;
  61. final double borderWidth;
  62. final VoidCallback? onTap;
  63. ImageColumnTextButton({
  64. required this.buttonSize,
  65. required this.image,
  66. Size? imageSize,
  67. required this.text,
  68. this.textStyle,
  69. this.space = 4,
  70. this.bgColor = Colors.white,
  71. this.borderRadius = 5,
  72. Color? borderColor,
  73. this.borderWidth = 1,
  74. this.onTap,
  75. })
  76. : imageSize = imageSize ?? buttonSize,
  77. borderColor = borderColor ?? bgColor
  78. ;
  79. @override
  80. Widget build(BuildContext context) {
  81. return GestureDetector(
  82. onTap: onTap,
  83. child: Opacity(
  84. opacity: onTap == null ? 0.5 : 1.0,
  85. child: Container(
  86. width: buttonSize.width,
  87. height: buttonSize.height,
  88. decoration: BoxDecoration(
  89. color: bgColor,
  90. shape: BoxShape.rectangle,
  91. borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
  92. border: Border.all(color: borderColor),
  93. ),
  94. child: Center(
  95. child: Column(
  96. mainAxisAlignment: MainAxisAlignment.center,
  97. crossAxisAlignment: CrossAxisAlignment.center,
  98. children: [
  99. Image.asset(
  100. image,
  101. width: imageSize.width,
  102. height: imageSize.height,
  103. ),
  104. SizedBox(height: space),
  105. Text(
  106. text,
  107. style: textStyle,
  108. textAlign: TextAlign.center,
  109. ),
  110. ],
  111. ),
  112. ),
  113. ),
  114. ),
  115. );
  116. }
  117. }
  118. class ImageRowTextButton extends StatelessWidget {
  119. final Size buttonSize;
  120. final String image;
  121. final Size imageSize;
  122. final String text;
  123. final TextStyle? textStyle;
  124. final double space;
  125. final Color bgColor;
  126. final double borderRadius;
  127. final Color borderColor;
  128. final double borderWidth;
  129. final VoidCallback? onTap;
  130. ImageRowTextButton({
  131. required this.buttonSize,
  132. required this.image,
  133. Size? imageSize,
  134. required this.text,
  135. this.textStyle,
  136. this.space = 2,
  137. this.bgColor = Colors.white,
  138. this.borderRadius = 5,
  139. Color? borderColor,
  140. this.borderWidth = 1,
  141. this.onTap,
  142. })
  143. : imageSize = imageSize ?? buttonSize,
  144. borderColor = borderColor ?? bgColor
  145. ;
  146. @override
  147. Widget build(BuildContext context) {
  148. return GestureDetector(
  149. onTap: onTap,
  150. child: Opacity(
  151. opacity: onTap == null ? 0.5 : 1.0,
  152. child: Container(
  153. width: buttonSize.width,
  154. height: buttonSize.height,
  155. decoration: BoxDecoration(
  156. color: bgColor,
  157. shape: BoxShape.rectangle,
  158. borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
  159. border: Border.all(color: borderColor),
  160. ),
  161. child: Center(
  162. child: Row(
  163. mainAxisAlignment: MainAxisAlignment.center,
  164. crossAxisAlignment: CrossAxisAlignment.center,
  165. children: [
  166. Image.asset(
  167. image,
  168. width: imageSize.width,
  169. height: imageSize.height,
  170. ),
  171. SizedBox(width: space),
  172. Text(
  173. text,
  174. style: textStyle,
  175. textAlign: TextAlign.left,
  176. ),
  177. ],
  178. ),
  179. ),
  180. ),
  181. ),
  182. );
  183. }
  184. }