submit_btn.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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: textColor ?? Colors.white,
  58. )
  59. : Row(
  60. mainAxisAlignment: MainAxisAlignment.center,
  61. children: [
  62. if (prefixIcon != null) ...[
  63. prefixIcon!,
  64. 10.horizontalSpace,
  65. ],
  66. Text(
  67. text,
  68. style: TextStyle(
  69. color: textColor ?? Colors.white,
  70. fontSize: fontSize ?? 16.sp,
  71. height: 1.2,
  72. fontWeight: FontWeight.w500,
  73. fontFeatures: fontFeatures ?? [],
  74. ),
  75. ),
  76. ],
  77. ),
  78. ),
  79. ),
  80. ),
  81. );
  82. }
  83. }
  84. class SubmitSvgButton extends StatelessWidget {
  85. final String svgPath;
  86. final double? svgWidth;
  87. final Color? svgColor;
  88. final String text;
  89. final VoidCallback? onPressed;
  90. final bool enabled;
  91. final Color? textColor;
  92. final Color? bgColor;
  93. final Color? borderColor;
  94. final double? fontSize;
  95. final bool isLoading;
  96. final double? width;
  97. final double height;
  98. const SubmitSvgButton({
  99. super.key,
  100. required this.svgPath,
  101. required this.text,
  102. this.svgColor,
  103. this.svgWidth,
  104. this.onPressed,
  105. this.enabled = true,
  106. this.textColor,
  107. this.bgColor,
  108. this.borderColor,
  109. this.fontSize,
  110. this.isLoading = false,
  111. this.width,
  112. this.height = 54,
  113. });
  114. @override
  115. Widget build(BuildContext context) {
  116. final prefixIcon = SvgPicture.asset(
  117. svgPath,
  118. colorFilter: svgColor != null
  119. ? ColorFilter.mode(svgColor!, BlendMode.srcIn)
  120. : null,
  121. width: svgWidth ?? 24.w,
  122. height: svgWidth ?? 24.w,
  123. );
  124. return SubmitButton(
  125. text: text,
  126. onPressed: onPressed,
  127. enabled: enabled,
  128. textColor: textColor,
  129. bgColor: bgColor,
  130. borderColor: borderColor,
  131. fontSize: fontSize,
  132. isLoading: isLoading,
  133. width: width,
  134. height: height,
  135. prefixIcon: prefixIcon,
  136. );
  137. }
  138. }
  139. class SubmitIconButton extends StatelessWidget {
  140. final IconData iconData;
  141. final String text;
  142. final double? iconSize;
  143. final VoidCallback? onPressed;
  144. final bool enabled;
  145. final Color? textColor;
  146. final Color? bgColor;
  147. final Color? borderColor;
  148. final double? fontSize;
  149. final bool isLoading;
  150. final double? width;
  151. final double height;
  152. final List<FontFeature>? fontFeatures;
  153. const SubmitIconButton({
  154. super.key,
  155. required this.iconData,
  156. required this.text,
  157. this.iconSize,
  158. this.onPressed,
  159. this.enabled = true,
  160. this.textColor,
  161. this.bgColor,
  162. this.borderColor,
  163. this.fontSize,
  164. this.isLoading = false,
  165. this.width,
  166. this.height = 54,
  167. this.fontFeatures,
  168. });
  169. @override
  170. Widget build(BuildContext context) {
  171. final prefixIcon = Icon(
  172. iconData,
  173. size: iconSize ?? 20.w,
  174. color: textColor ?? Get.reactiveTheme.textTheme.bodyLarge!.color,
  175. );
  176. return SubmitButton(
  177. text: text,
  178. onPressed: onPressed,
  179. enabled: enabled,
  180. textColor: textColor,
  181. bgColor: bgColor,
  182. borderColor: borderColor,
  183. fontSize: fontSize,
  184. isLoading: isLoading,
  185. width: width,
  186. height: height,
  187. prefixIcon: prefixIcon,
  188. fontFeatures: fontFeatures,
  189. );
  190. }
  191. }