submit_btn.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_spinkit/flutter_spinkit.dart';
  4. import 'package:flutter_svg/svg.dart';
  5. import 'package:get/get.dart';
  6. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  7. import 'click_opacity.dart';
  8. class SubmitButton extends StatelessWidget {
  9. final String text;
  10. final VoidCallback? onPressed;
  11. final bool enabled;
  12. final Color? textColor;
  13. final Color? bgColor;
  14. final Color? borderColor;
  15. final double? fontSize;
  16. final bool isLoading;
  17. final double? width;
  18. final double height;
  19. final Widget? prefixIcon;
  20. final List<FontFeature>? fontFeatures;
  21. const SubmitButton({
  22. super.key,
  23. required this.text,
  24. this.onPressed,
  25. this.enabled = true,
  26. this.textColor,
  27. this.bgColor,
  28. this.borderColor,
  29. this.fontSize,
  30. this.isLoading = false,
  31. this.width,
  32. this.height = 52,
  33. this.prefixIcon,
  34. this.fontFeatures,
  35. });
  36. @override
  37. Widget build(BuildContext context) {
  38. return ClickOpacity(
  39. onTap: isLoading ? null : onPressed,
  40. child: Opacity(
  41. opacity: enabled ? 1 : 0.3,
  42. child: Container(
  43. width: width ?? double.infinity,
  44. height: height.w,
  45. decoration: BoxDecoration(
  46. color: bgColor ?? Get.reactiveTheme.primaryColor,
  47. borderRadius: BorderRadius.circular(12.r),
  48. border: borderColor != null
  49. ? Border.all(color: borderColor!, width: 1.w)
  50. : null,
  51. ),
  52. child: Center(
  53. child: isLoading
  54. ? SpinKitRing(
  55. size: 20.w,
  56. lineWidth: 2.w,
  57. color:
  58. textColor ??
  59. Get.reactiveTheme.textTheme.bodyLarge!.color!,
  60. )
  61. : Row(
  62. mainAxisAlignment: MainAxisAlignment.center,
  63. children: [
  64. if (prefixIcon != null) ...[
  65. prefixIcon!,
  66. 10.horizontalSpace,
  67. ],
  68. Text(
  69. text,
  70. style: TextStyle(
  71. color:
  72. textColor ??
  73. Get.reactiveTheme.textTheme.bodyLarge!.color,
  74. fontSize: fontSize ?? 16.sp,
  75. height: 1.2,
  76. fontWeight: FontWeight.w500,
  77. fontFeatures: fontFeatures ?? [],
  78. ),
  79. ),
  80. ],
  81. ),
  82. ),
  83. ),
  84. ),
  85. );
  86. }
  87. }
  88. class SubmitSvgButton extends StatelessWidget {
  89. final String svgPath;
  90. final double? svgWidth;
  91. final Color? svgColor;
  92. final String text;
  93. final VoidCallback? onPressed;
  94. final bool enabled;
  95. final Color? textColor;
  96. final Color? bgColor;
  97. final Color? borderColor;
  98. final double? fontSize;
  99. final bool isLoading;
  100. final double? width;
  101. final double height;
  102. const SubmitSvgButton({
  103. super.key,
  104. required this.svgPath,
  105. required this.text,
  106. this.svgColor,
  107. this.svgWidth,
  108. this.onPressed,
  109. this.enabled = true,
  110. this.textColor,
  111. this.bgColor,
  112. this.borderColor,
  113. this.fontSize,
  114. this.isLoading = false,
  115. this.width,
  116. this.height = 54,
  117. });
  118. @override
  119. Widget build(BuildContext context) {
  120. final prefixIcon = SvgPicture.asset(
  121. svgPath,
  122. colorFilter: svgColor != null
  123. ? ColorFilter.mode(svgColor!, BlendMode.srcIn)
  124. : null,
  125. width: svgWidth ?? 24.w,
  126. height: svgWidth ?? 24.w,
  127. );
  128. return SubmitButton(
  129. text: text,
  130. onPressed: onPressed,
  131. enabled: enabled,
  132. textColor: textColor,
  133. bgColor: bgColor,
  134. borderColor: borderColor,
  135. fontSize: fontSize,
  136. isLoading: isLoading,
  137. width: width,
  138. height: height,
  139. prefixIcon: prefixIcon,
  140. );
  141. }
  142. }
  143. class SubmitIconButton extends StatelessWidget {
  144. final IconData iconData;
  145. final String text;
  146. final double? iconSize;
  147. final VoidCallback? onPressed;
  148. final bool enabled;
  149. final Color? textColor;
  150. final Color? bgColor;
  151. final Color? borderColor;
  152. final double? fontSize;
  153. final bool isLoading;
  154. final double? width;
  155. final double height;
  156. final List<FontFeature>? fontFeatures;
  157. const SubmitIconButton({
  158. super.key,
  159. required this.iconData,
  160. required this.text,
  161. this.iconSize,
  162. this.onPressed,
  163. this.enabled = true,
  164. this.textColor,
  165. this.bgColor,
  166. this.borderColor,
  167. this.fontSize,
  168. this.isLoading = false,
  169. this.width,
  170. this.height = 54,
  171. this.fontFeatures,
  172. });
  173. @override
  174. Widget build(BuildContext context) {
  175. final prefixIcon = Icon(
  176. iconData,
  177. size: iconSize ?? 20.w,
  178. color: textColor ?? Get.reactiveTheme.textTheme.bodyLarge!.color,
  179. );
  180. return SubmitButton(
  181. text: text,
  182. onPressed: onPressed,
  183. enabled: enabled,
  184. textColor: textColor,
  185. bgColor: bgColor,
  186. borderColor: borderColor,
  187. fontSize: fontSize,
  188. isLoading: isLoading,
  189. width: width,
  190. height: height,
  191. prefixIcon: prefixIcon,
  192. fontFeatures: fontFeatures,
  193. );
  194. }
  195. }