tips_dialog.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import 'package:flutter/material.dart';
  2. import 'package:fluttertoast/fluttertoast.dart';
  3. import 'package:gobang/themes/app_colors.dart';
  4. class TipsDialog {
  5. static Future<void> show(
  6. BuildContext context,
  7. String title,
  8. String tips,
  9. ) {
  10. return showGeneralDialog<void>(
  11. context: context,
  12. barrierDismissible: false,
  13. barrierLabel: 'dialog',
  14. barrierColor: const Color(0xB0070D10),
  15. transitionDuration: const Duration(milliseconds: 280),
  16. pageBuilder: (ctx, a1, a2) {
  17. return const SizedBox.shrink();
  18. },
  19. transitionBuilder: (ctx, anim, _, __) {
  20. final curved = CurvedAnimation(parent: anim, curve: Curves.easeOutBack);
  21. return FadeTransition(
  22. opacity: anim,
  23. child: ScaleTransition(
  24. scale: Tween(begin: 0.88, end: 1.0).animate(curved),
  25. child: Center(
  26. child: Material(
  27. color: Colors.transparent,
  28. child: Container(
  29. width: MediaQuery.of(ctx).size.width * 0.82,
  30. padding: const EdgeInsets.fromLTRB(24, 28, 24, 20),
  31. decoration: BoxDecoration(
  32. color: AppColors.ivory,
  33. borderRadius: BorderRadius.circular(28),
  34. boxShadow: [
  35. BoxShadow(
  36. color: Colors.black.withValues(alpha: 0.28),
  37. blurRadius: 40,
  38. offset: const Offset(0, 16),
  39. ),
  40. ],
  41. ),
  42. child: Column(
  43. mainAxisSize: MainAxisSize.min,
  44. children: [
  45. Container(
  46. width: 64,
  47. height: 64,
  48. decoration: BoxDecoration(
  49. shape: BoxShape.circle,
  50. gradient: LinearGradient(
  51. colors: title.contains('恭喜')
  52. ? const [
  53. AppColors.pumpkinSoft,
  54. AppColors.pumpkin,
  55. ]
  56. : const [Color(0xFF4A4A4A), Color(0xFF1A1A1A)],
  57. ),
  58. ),
  59. ),
  60. const SizedBox(height: 16),
  61. Text(
  62. title,
  63. style: const TextStyle(
  64. color: AppColors.ink,
  65. fontSize: 24,
  66. fontWeight: FontWeight.w800,
  67. ),
  68. ),
  69. const SizedBox(height: 8),
  70. Text(
  71. tips,
  72. textAlign: TextAlign.center,
  73. style: const TextStyle(
  74. color: Color(0xFF5A736A),
  75. fontSize: 14,
  76. height: 1.4,
  77. ),
  78. ),
  79. const SizedBox(height: 20),
  80. SizedBox(
  81. width: double.infinity,
  82. child: FilledButton(
  83. style: FilledButton.styleFrom(
  84. backgroundColor: title.contains('恭喜')
  85. ? AppColors.ink
  86. : AppColors.pumpkin,
  87. foregroundColor: AppColors.ivory,
  88. padding: const EdgeInsets.symmetric(vertical: 14),
  89. shape: RoundedRectangleBorder(
  90. borderRadius: BorderRadius.circular(14),
  91. ),
  92. ),
  93. onPressed: () => Navigator.of(ctx).pop(),
  94. child: Text(
  95. title.contains('恭喜') ? '再来一局' : '确定',
  96. style: const TextStyle(fontWeight: FontWeight.w700),
  97. ),
  98. ),
  99. ),
  100. ],
  101. ),
  102. ),
  103. ),
  104. ),
  105. ),
  106. );
  107. },
  108. );
  109. }
  110. static Future<bool?> showByChoose(
  111. BuildContext context,
  112. String title,
  113. String tips,
  114. String yes,
  115. String no,
  116. ) {
  117. return showGeneralDialog<bool>(
  118. context: context,
  119. barrierDismissible: false,
  120. barrierLabel: 'choose',
  121. barrierColor: const Color(0x99070D10),
  122. transitionDuration: const Duration(milliseconds: 240),
  123. pageBuilder: (ctx, a1, a2) => const SizedBox.shrink(),
  124. transitionBuilder: (ctx, anim, _, __) {
  125. return FadeTransition(
  126. opacity: anim,
  127. child: ScaleTransition(
  128. scale: Tween(begin: 0.92, end: 1.0).animate(
  129. CurvedAnimation(parent: anim, curve: Curves.easeOutCubic),
  130. ),
  131. child: Center(
  132. child: Material(
  133. color: Colors.transparent,
  134. child: Container(
  135. width: MediaQuery.of(ctx).size.width * 0.8,
  136. padding: const EdgeInsets.all(24),
  137. decoration: BoxDecoration(
  138. color: AppColors.ivory,
  139. borderRadius: BorderRadius.circular(24),
  140. ),
  141. child: Column(
  142. mainAxisSize: MainAxisSize.min,
  143. children: [
  144. Text(
  145. title,
  146. style: const TextStyle(
  147. color: AppColors.ink,
  148. fontSize: 20,
  149. fontWeight: FontWeight.w800,
  150. ),
  151. ),
  152. const SizedBox(height: 10),
  153. Text(
  154. tips,
  155. textAlign: TextAlign.center,
  156. style: const TextStyle(
  157. color: Color(0xFF5A736A),
  158. fontSize: 14,
  159. ),
  160. ),
  161. const SizedBox(height: 20),
  162. Row(
  163. children: [
  164. Expanded(
  165. child: TextButton(
  166. style: TextButton.styleFrom(
  167. backgroundColor: AppColors.mist,
  168. foregroundColor: AppColors.ink,
  169. padding:
  170. const EdgeInsets.symmetric(vertical: 12),
  171. shape: RoundedRectangleBorder(
  172. borderRadius: BorderRadius.circular(12),
  173. ),
  174. ),
  175. onPressed: () => Navigator.of(ctx).pop(false),
  176. child: Text(no),
  177. ),
  178. ),
  179. const SizedBox(width: 12),
  180. Expanded(
  181. child: FilledButton(
  182. style: FilledButton.styleFrom(
  183. backgroundColor: title.contains('投降')
  184. ? AppColors.pumpkin
  185. : AppColors.ink,
  186. foregroundColor: AppColors.ivory,
  187. padding:
  188. const EdgeInsets.symmetric(vertical: 12),
  189. shape: RoundedRectangleBorder(
  190. borderRadius: BorderRadius.circular(12),
  191. ),
  192. ),
  193. onPressed: () => Navigator.of(ctx).pop(true),
  194. child: Text(yes),
  195. ),
  196. ),
  197. ],
  198. ),
  199. ],
  200. ),
  201. ),
  202. ),
  203. ),
  204. ),
  205. );
  206. },
  207. );
  208. }
  209. static void toast(String message) {
  210. Fluttertoast.showToast(msg: message, gravity: ToastGravity.CENTER);
  211. }
  212. }