imageButton.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. textAlign: TextAlign.center,
  113. ),
  114. ],
  115. ),
  116. ),
  117. ),
  118. ),
  119. );
  120. }
  121. }
  122. class ImageRowTextButton extends StatelessWidget {
  123. final Size buttonSize;
  124. final String image;
  125. final Size imageSize;
  126. final String text;
  127. final TextStyle? textStyle;
  128. final double space;
  129. final Color bgColor;
  130. final double borderRadius;
  131. final Color borderColor;
  132. final double borderWidth;
  133. final VoidCallback? onTap;
  134. ImageRowTextButton({
  135. required Size buttonSize,
  136. required this.image,
  137. Size? imageSize,
  138. required this.text,
  139. this.textStyle,
  140. this.space = 2,
  141. Color bgColor = Colors.white,
  142. this.borderRadius = 5,
  143. Color? borderColor,
  144. this.borderWidth = 1,
  145. this.onTap,
  146. })
  147. : buttonSize = buttonSize,
  148. imageSize = imageSize ?? buttonSize,
  149. bgColor = bgColor,
  150. borderColor = borderColor ?? bgColor
  151. ;
  152. @override
  153. Widget build(BuildContext context) {
  154. return GestureDetector(
  155. onTap: onTap,
  156. child: Opacity(
  157. opacity: onTap == null ? 0.5 : 1.0,
  158. child: Container(
  159. width: buttonSize.width,
  160. height: buttonSize.height,
  161. decoration: BoxDecoration(
  162. color: bgColor,
  163. shape: BoxShape.rectangle,
  164. borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
  165. border: Border.all(color: borderColor),
  166. ),
  167. child: Center(
  168. child: Row(
  169. mainAxisAlignment: MainAxisAlignment.center,
  170. crossAxisAlignment: CrossAxisAlignment.center,
  171. children: [
  172. Image.asset(
  173. image,
  174. width: imageSize.width,
  175. height: imageSize.height,
  176. ),
  177. SizedBox(width: space),
  178. Text(
  179. text,
  180. style: textStyle,
  181. textAlign: TextAlign.left,
  182. ),
  183. ],
  184. ),
  185. ),
  186. ),
  187. ),
  188. );
  189. }
  190. }