button.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import 'package:ctjt_flutter/common/styles.dart';
  2. import 'package:ctjt_flutter/common/utils.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/rendering.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. /* ---------------------------------大提交按钮-------------------------------- */
  7. class BigSButton extends StatelessWidget {
  8. static var _defaultPadding = EdgeInsets.only(top: 75.h);
  9. BigSButton(
  10. {Key? key,
  11. required this.text,
  12. this.padding,
  13. this.milliseconds = 500,
  14. this.vibrateDuration = Utils.DefaultVibrateDuration,
  15. required this.onPressed})
  16. : super(key: key);
  17. final String text;
  18. final EdgeInsetsGeometry? padding;
  19. final Function onPressed;
  20. final int milliseconds;
  21. final int vibrateDuration;
  22. @override
  23. Widget build(BuildContext context) {
  24. bool _isCan = true;
  25. return Container(
  26. // 设定尺寸的容器
  27. width: double.infinity, // 占满宽度
  28. height: 230.0.h,
  29. padding: null == this.padding ? _defaultPadding : this.padding,
  30. child: ElevatedButton(
  31. style: ButtonStyle(
  32. backgroundColor: MaterialStateProperty.all(Colors.white),
  33. foregroundColor: MaterialStateProperty.all(Colors.white),
  34. shape: MaterialStateProperty.all(RoundedRectangleBorder(
  35. borderRadius: BorderRadius.circular(ScreenUtil().radius(20)))),
  36. elevation: MaterialStateProperty.all(ScreenUtil().radius(7.5)),
  37. ),
  38. child: Text(this.text, style: Styles.btnFontStyle),
  39. // 圆角
  40. onPressed: () {
  41. Utils.vibrate(duration: this.vibrateDuration); // 震动
  42. if (_isCan) {
  43. this.onPressed();
  44. _isCan = false;
  45. // 不能多次点击
  46. Future.delayed(Duration(milliseconds: this.milliseconds), () {
  47. _isCan = true;
  48. });
  49. }
  50. },
  51. ),
  52. );
  53. }
  54. }
  55. /* --------------------------------大文本按钮--------------------------------- */
  56. class BigTButton extends StatelessWidget {
  57. static var _defaultPadding = EdgeInsets.only(top: 25.h);
  58. BigTButton(
  59. {Key? key,
  60. required this.text,
  61. this.padding,
  62. this.milliseconds = 500,
  63. this.vibrateDuration = Utils.DefaultVibrateDuration,
  64. required this.onPressed})
  65. : super(key: key);
  66. final String text;
  67. final EdgeInsetsGeometry? padding;
  68. final Function onPressed;
  69. final int milliseconds;
  70. final int vibrateDuration;
  71. @override
  72. Widget build(BuildContext context) {
  73. bool _isCan = true;
  74. return Padding(
  75. padding: null == this.padding ? _defaultPadding : this.padding!,
  76. child: OutlinedButton(
  77. style: ButtonStyle(
  78. padding: MaterialStateProperty.all(EdgeInsets.all(0)),
  79. side: MaterialStateProperty.all(BorderSide.none),
  80. ),
  81. child: Text(this.text,
  82. textAlign: TextAlign.left,
  83. overflow: TextOverflow.ellipsis,
  84. style: Styles.btnFontStyle),
  85. //color: Colors.red,
  86. onPressed: () {
  87. Utils.vibrate(duration: this.vibrateDuration); // 震动
  88. if (_isCan) {
  89. this.onPressed();
  90. _isCan = false;
  91. // 不能多次点击
  92. Future.delayed(Duration(milliseconds: this.milliseconds), () {
  93. _isCan = true;
  94. });
  95. }
  96. },
  97. ),
  98. );
  99. }
  100. }
  101. /* ----------------------------------图标按钮--------------------------------- */
  102. class IButton extends IconButton {
  103. IButton({
  104. Key? key,
  105. double iconSize = 24.0,
  106. VisualDensity? visualDensity,
  107. EdgeInsetsGeometry padding = const EdgeInsets.all(8.0),
  108. AlignmentGeometry alignment = Alignment.center,
  109. double? splashRadius,
  110. required Widget icon,
  111. Color? color,
  112. Color? focusColor,
  113. Color? hoverColor,
  114. Color? highlightColor,
  115. Color? splashColor,
  116. Color? disabledColor,
  117. required VoidCallback onPressed,
  118. MouseCursor mouseCursor = SystemMouseCursors.click,
  119. FocusNode? focusNode,
  120. bool autofocus = false,
  121. String? tooltip,
  122. bool enableFeedback = true,
  123. BoxConstraints? constraints,
  124. this.vibrateDuration = Utils.DefaultVibrateDuration,
  125. }) : super(
  126. key: key,
  127. iconSize: iconSize,
  128. visualDensity: visualDensity,
  129. padding: padding,
  130. alignment: alignment,
  131. splashRadius: splashRadius,
  132. icon: icon,
  133. color: color,
  134. focusColor: focusColor,
  135. hoverColor: hoverColor,
  136. highlightColor: highlightColor,
  137. splashColor: splashColor,
  138. disabledColor: disabledColor,
  139. onPressed: () {
  140. Utils.vibrate(duration: vibrateDuration); // 震动
  141. onPressed();
  142. },
  143. mouseCursor: mouseCursor,
  144. focusNode: focusNode,
  145. autofocus: autofocus,
  146. tooltip: tooltip,
  147. enableFeedback: enableFeedback,
  148. constraints: constraints,
  149. );
  150. final int vibrateDuration;
  151. }
  152. /* ----------------------------------文本按钮--------------------------------- */
  153. class TButton extends TextButton {
  154. TButton({
  155. Key? key,
  156. required VoidCallback onPressed,
  157. VoidCallback? onLongPress,
  158. ButtonStyle? style,
  159. FocusNode? focusNode,
  160. bool autofocus = false,
  161. Clip clipBehavior = Clip.none,
  162. required Widget child,
  163. this.vibrateDuration = Utils.DefaultVibrateDuration,
  164. }) : super(
  165. key: key,
  166. onPressed: () {
  167. Utils.vibrate(duration: vibrateDuration); // 震动
  168. onPressed();
  169. },
  170. onLongPress: onLongPress,
  171. style: style,
  172. focusNode: focusNode,
  173. autofocus: autofocus,
  174. clipBehavior: clipBehavior,
  175. child: child,
  176. );
  177. final int vibrateDuration;
  178. }