alert_widget.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import 'package:fast/constants.dart';
  2. import 'package:fast/utils/size_fit.dart';
  3. import 'package:flutter/material.dart';
  4. // ignore: must_be_immutable
  5. class AlertWidget extends StatefulWidget {
  6. String title = '';
  7. // String message = '';
  8. String confirm = '确定';
  9. bool isHiddenCancel = false;
  10. VoidCallback confirmCallback;
  11. AlertWidget(
  12. {Key? key,
  13. required this.title,
  14. required this.confirm,
  15. required this.confirmCallback,
  16. bool? hideCancel})
  17. : super(key: key) {
  18. if (hideCancel != null) {
  19. isHiddenCancel = hideCancel;
  20. }
  21. }
  22. @override
  23. State<AlertWidget> createState() => _AlertWidgetState();
  24. }
  25. class _AlertWidgetState extends State<AlertWidget>
  26. with SingleTickerProviderStateMixin {
  27. late AnimationController controller;
  28. late Animation animation;
  29. late Animation alphaAnimation;
  30. @override
  31. void initState() {
  32. controller = AnimationController(
  33. vsync: this, duration: const Duration(milliseconds: 300));
  34. animation = Tween(begin: 40.0, end: 0.0).animate(controller);
  35. alphaAnimation = Tween(begin: 0.0, end: 1.0).animate(controller);
  36. controller.addListener(() {
  37. setState(() {});
  38. });
  39. controller.forward();
  40. super.initState();
  41. }
  42. @override
  43. void dispose() {
  44. controller.dispose();
  45. super.dispose();
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return Material(
  50. color: Colors.transparent,
  51. child: Opacity(
  52. opacity: alphaAnimation.value,
  53. child: Center(
  54. child: Container(
  55. margin: EdgeInsets.only(top: animation.value),
  56. padding: EdgeInsets.fromLTRB(24.px, 32.px, 24.px, 32.px),
  57. width: 268.px,
  58. decoration: BoxDecoration(
  59. color: const Color(0xFF142133),
  60. borderRadius: BorderRadius.all(Radius.circular(32.px))),
  61. child: Column(
  62. mainAxisSize: MainAxisSize.min,
  63. children: [
  64. Text(
  65. widget.title,
  66. style: TextStyle(
  67. color: Colors.white,
  68. fontSize: 16.px,
  69. fontWeight: FontWeight.bold,
  70. height: 1.5,
  71. ),
  72. textAlign: TextAlign.center,
  73. ),
  74. SizedBox(
  75. height: 18.px,
  76. ),
  77. Row(
  78. children: [
  79. if (widget.isHiddenCancel == false)
  80. Expanded(
  81. child: Container(
  82. child: TextButton(
  83. onPressed: () => Navigator.of(context).pop(),
  84. child: Text(
  85. '取消',
  86. style: TextStyle(
  87. color: const Color(0xFFC4CCDA),
  88. fontSize: 14.px,
  89. fontWeight: FontWeight.bold),
  90. )),
  91. height: 42.px,
  92. decoration: BoxDecoration(
  93. color: const Color(0x33C4CCDA),
  94. borderRadius:
  95. BorderRadius.all(Radius.circular(21.px))),
  96. )),
  97. if (widget.isHiddenCancel == false)
  98. SizedBox(
  99. width: 12.px,
  100. ),
  101. Expanded(
  102. child: Container(
  103. child: TextButton(
  104. onPressed: widget.confirmCallback,
  105. child: Text(
  106. widget.confirm,
  107. style: TextStyle(
  108. color: kBgColor,
  109. fontSize: 14.px,
  110. fontWeight: FontWeight.bold),
  111. )),
  112. height: 42.px,
  113. decoration: BoxDecoration(
  114. color: kThemeColor,
  115. borderRadius: BorderRadius.all(Radius.circular(21.px))),
  116. ))
  117. ],
  118. )
  119. ],
  120. ),
  121. )),
  122. ),
  123. );
  124. }
  125. }
  126. /*
  127. class AlertWidget extends Dialog {
  128. String title = '';
  129. // String message = '';
  130. String confirm = '确定';
  131. VoidCallback confirmCallback;
  132. AlertWidget(
  133. {Key? key,
  134. required this.title,
  135. required this.confirm,
  136. required this.confirmCallback})
  137. : super(key: key);
  138. @override
  139. Widget build(BuildContext context) {
  140. return Material(
  141. color: Colors.transparent,
  142. child: Center(
  143. child: Container(
  144. padding: EdgeInsets.fromLTRB(24.px, 32.px, 24.px, 32.px),
  145. width: 268.px,
  146. decoration: BoxDecoration(
  147. color: const Color(0xFF142133),
  148. borderRadius: BorderRadius.all(Radius.circular(32.px))),
  149. child: Column(
  150. mainAxisSize: MainAxisSize.min,
  151. children: [
  152. Text(
  153. title,
  154. style: TextStyle(
  155. color: Colors.white,
  156. fontSize: 16.px,
  157. fontWeight: FontWeight.bold,
  158. height: 1.5,
  159. ),
  160. textAlign: TextAlign.center,
  161. ),
  162. SizedBox(
  163. height: 18.px,
  164. ),
  165. Row(
  166. children: [
  167. Expanded(
  168. child: Container(
  169. child: TextButton(
  170. onPressed: () => Navigator.of(context).pop(),
  171. child: Text(
  172. '取消',
  173. style: TextStyle(
  174. color: const Color(0xFFC4CCDA),
  175. fontSize: 14.px,
  176. fontWeight: FontWeight.bold),
  177. )),
  178. height: 42.px,
  179. decoration: BoxDecoration(
  180. color: const Color(0x33C4CCDA),
  181. borderRadius: BorderRadius.all(Radius.circular(21.px))),
  182. )),
  183. SizedBox(
  184. width: 12.px,
  185. ),
  186. Expanded(
  187. child: Container(
  188. child: TextButton(
  189. onPressed: confirmCallback,
  190. child: Text(
  191. confirm,
  192. style: TextStyle(
  193. color: kBgColor,
  194. fontSize: 14.px,
  195. fontWeight: FontWeight.bold),
  196. )),
  197. height: 42.px,
  198. decoration: BoxDecoration(
  199. color: kThemeColor,
  200. borderRadius: BorderRadius.all(Radius.circular(21.px))),
  201. ))
  202. ],
  203. )
  204. ],
  205. ),
  206. )),
  207. );
  208. }
  209. }*/