imageButton.dart 5.0 KB

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