PopMenus.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_habit/common/I18N.dart';
  3. import 'package:flutter_habit/provider/UserProvider.dart';
  4. import 'package:provider/provider.dart';
  5. import 'SliderConfirm.dart';
  6. import 'UserInfoPopMenuContext.dart';
  7. class PopMenus {
  8. static Future<void> confirm({
  9. required BuildContext context,
  10. Widget? content,
  11. required Function function,
  12. }) async {
  13. await baseAlertMenu<int>(
  14. context: context,
  15. content: content ?? Text(I18N.of("继续该操作吗?")),
  16. actions: [
  17. TextButton(
  18. child: Text(I18N.of("取消")),
  19. onPressed: () {
  20. Navigator.of(context).pop(0);
  21. },
  22. ),
  23. TextButton(
  24. child: Text(I18N.of("确定")),
  25. onPressed: () {
  26. Navigator.of(context).pop(1);
  27. },
  28. ),
  29. ],
  30. ).then<int>((value) {
  31. if (value == 1) {
  32. function();
  33. }
  34. return value!;
  35. });
  36. }
  37. static Future<void> sliderConfirm({
  38. required BuildContext context,
  39. Widget? content,
  40. required Function function,
  41. }) async {
  42. await baseMenu<int>(
  43. context: context,
  44. children: <Widget>[
  45. Padding(
  46. padding: EdgeInsets.all(24),
  47. child: DefaultTextStyle(
  48. style: Theme.of(context).textTheme.titleLarge!,
  49. child: content ?? Text(I18N.of("继续该操作吗?")),
  50. ),
  51. ),
  52. Padding(
  53. padding: EdgeInsets.only(left: 15, right: 15, bottom: 15),
  54. child: SliderConfirm(
  55. function: () => Navigator.of(context).pop(1),
  56. ),
  57. ),
  58. ],
  59. contentPadding: EdgeInsets.all(0),
  60. ).then<int>((value) {
  61. if (value == 1) {
  62. function();
  63. }
  64. return value!;
  65. });
  66. }
  67. static Future<void> attention({
  68. required BuildContext context,
  69. Widget? content,
  70. }) async {
  71. await baseAlertMenu(
  72. context: context,
  73. content: content,
  74. );
  75. }
  76. static Future<T?> baseAlertMenu<T>({
  77. required BuildContext context,
  78. Widget? title,
  79. Widget? content,
  80. List<Widget>? actions,
  81. }) async {
  82. return await showDialog(
  83. context: context,
  84. builder: (context) => AlertDialog(
  85. title: title ?? Text(I18N.of("注意")),
  86. content: content ?? Text(I18N.of("注意")),
  87. actions: actions ??
  88. <Widget>[
  89. TextButton(
  90. child: Text(I18N.of("确定")),
  91. onPressed: () {
  92. Navigator.of(context).pop();
  93. },
  94. ),
  95. ],
  96. ),
  97. );
  98. }
  99. static Future<T?> baseMenu<T>({
  100. required BuildContext context,
  101. Widget? title,
  102. List<Widget>? children,
  103. EdgeInsetsGeometry? contentPadding,
  104. }) async {
  105. return await showDialog(
  106. context: context,
  107. builder: (context) => SimpleDialog(
  108. title: title ?? Text(I18N.of("注意")),
  109. children: children ?? [Text(I18N.of("注意"))],
  110. contentPadding:
  111. contentPadding ?? EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0),
  112. ),
  113. );
  114. }
  115. static Future<String> datePicker({
  116. required BuildContext context,
  117. }) async {
  118. return await showDatePicker(
  119. context: context,
  120. initialDate: DateTime.now().subtract(Duration(days: 3650)),
  121. firstDate: DateTime.now().subtract(Duration(days: 36500)),
  122. lastDate: DateTime.now(),
  123. initialDatePickerMode: DatePickerMode.year,
  124. ).then((onValue) {
  125. if (onValue != null) {
  126. return onValue.toIso8601String().toString();
  127. }
  128. return null;
  129. });
  130. }
  131. static Future<String?> userInfo({
  132. required BuildContext context,
  133. required int? uid,
  134. }) async {
  135. return await baseMenu(
  136. context: context,
  137. title: Text(I18N.of("信息")),
  138. children: <Widget>[
  139. UserInfoPopMenuContext(uid),
  140. ],
  141. contentPadding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 10),
  142. );
  143. }
  144. static Future<void> ban(BuildContext context) async {
  145. await baseMenu(
  146. context: context,
  147. contentPadding: EdgeInsets.all(16),
  148. children: [
  149. Row(
  150. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  151. children: <Widget>[
  152. Icon(
  153. Icons.warning,
  154. size: 80,
  155. color: Theme.of(context).unselectedWidgetColor,
  156. ),
  157. Container(),
  158. Container(
  159. child: Text(
  160. I18N.of("您的账号由于存在恶意刷金币行为已被系统限制金币获取"),
  161. maxLines: 3,
  162. ),
  163. width: 200,
  164. ),
  165. ],
  166. ),
  167. ],
  168. );
  169. }
  170. static Future<void> coinAdd({
  171. required BuildContext context,
  172. required int addedCoins,
  173. }) async {
  174. await baseMenu(
  175. context: context,
  176. title: Text(I18N.of("打卡成功")),
  177. children: [
  178. Row(
  179. mainAxisAlignment: MainAxisAlignment.center,
  180. crossAxisAlignment: CrossAxisAlignment.end,
  181. children: <Widget>[
  182. Icon(
  183. Icons.monetization_on,
  184. size: 80,
  185. color: Theme.of(context).colorScheme.secondary,
  186. ),
  187. Text(
  188. " + ",
  189. style: TextStyle(
  190. fontSize: 40,
  191. ),
  192. ),
  193. Text(
  194. " ${addedCoins.toString()} ",
  195. style: TextStyle(
  196. fontSize: 60,
  197. color: Theme.of(context).colorScheme.secondary,
  198. ),
  199. ),
  200. ],
  201. ),
  202. Container(height: 10,),
  203. Center(
  204. child: Text(
  205. "${Provider.of<UserProvider>(context, listen: false).coins} -> ${Provider.of<UserProvider>(context, listen: false).coins! + addedCoins}",
  206. style: TextStyle(
  207. color: Theme.of(context).unselectedWidgetColor,
  208. ),
  209. ),
  210. ),
  211. ],
  212. );
  213. }
  214. }