CheckinDialog.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:wanna_battle/styles/colors.dart';
  4. import 'package:wanna_battle/styles/totast.dart';
  5. import '../styles/colors.dart';
  6. import '../model/CheckinConfig.dart';
  7. import '../net/HttpManager.dart';
  8. void showCheckinDialog(BuildContext context) {
  9. showGeneralDialog(
  10. context: context,
  11. pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
  12. return Center(
  13. child: Material(
  14. color: Colors.transparent,
  15. child: _CheckinDialog(),
  16. ),
  17. );
  18. },
  19. barrierDismissible: true,
  20. barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
  21. barrierColor: Colors.black26,
  22. transitionBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  23. final curvedValue = Curves.easeInOutBack.transform(animation.value) - 1.0;
  24. return Transform(
  25. transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
  26. child: Opacity(
  27. opacity: animation.value,
  28. child: child,
  29. ),
  30. );
  31. },
  32. transitionDuration: const Duration(milliseconds: 300),
  33. );
  34. }
  35. class _CheckinDialog extends StatefulWidget {
  36. @override
  37. State<StatefulWidget> createState() {
  38. return _CheckinDialogState();
  39. }
  40. }
  41. class _CheckinDialogState extends State<_CheckinDialog> {
  42. Map<int, CheckinConfig> record;
  43. bool todayChecked = false;
  44. Future<void> getRecords() async {
  45. final res = await HttpManager.get('checkinRecord/weekRecord');
  46. if (res.success) {
  47. Map<int, CheckinConfig> map = {};
  48. res.data.forEach((k, v) {
  49. map[int.parse(k)] = CheckinConfig.fromJson(v);
  50. });
  51. bool todayChecked = false;
  52. if (map[DateTime.now().weekday] != null && map[DateTime.now().weekday].checked == 1) {
  53. todayChecked = true;
  54. }
  55. setState(() {
  56. record = map;
  57. this.todayChecked = todayChecked;
  58. });
  59. }
  60. }
  61. Future<void> checkin() async {
  62. Toast.show(context, '加载中', -1, 'loading');
  63. final res = await HttpManager.get('checkinRecord/checkin');
  64. print(res.data.toString());
  65. Toast.hide();
  66. if (res.success) {
  67. Toast.show(context, '签到成功', 1500, 'info');
  68. } else {
  69. Toast.show(context, res.error, 1500, 'info');
  70. }
  71. Navigator.of(context).pop();
  72. }
  73. @override
  74. void initState() {
  75. super.initState();
  76. Future.delayed(Duration.zero, () async {
  77. getRecords();
  78. });
  79. }
  80. @override
  81. Widget build(BuildContext context) {
  82. return Container(
  83. width: 330,
  84. height: 390,
  85. decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))),
  86. child: record == null
  87. ? null
  88. : Column(
  89. crossAxisAlignment: CrossAxisAlignment.center,
  90. mainAxisAlignment: MainAxisAlignment.center,
  91. children: <Widget>[
  92. Text(
  93. '每日签到',
  94. style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
  95. ),
  96. Container(
  97. margin: EdgeInsets.only(top: 30),
  98. child: Row(
  99. mainAxisAlignment: MainAxisAlignment.center,
  100. children: <Widget>[
  101. item(record[1]),
  102. item(record[2]),
  103. item(record[3]),
  104. item(record[4]),
  105. ],
  106. ),
  107. ),
  108. Container(
  109. margin: EdgeInsets.only(top: 25),
  110. child: Row(
  111. mainAxisAlignment: MainAxisAlignment.center,
  112. children: <Widget>[
  113. item(record[5]),
  114. item(record[6]),
  115. ],
  116. ),
  117. ),
  118. todayChecked
  119. ? Container(
  120. margin: EdgeInsets.only(top: 40),
  121. child: MaterialButton(
  122. minWidth: 220,
  123. elevation: 0,
  124. highlightElevation: 0,
  125. color: Color(0xFF4F5C87),
  126. child: Text(
  127. '今日已签到',
  128. style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
  129. ),
  130. onPressed: () {
  131. Navigator.of(context).pop();
  132. },
  133. ),
  134. )
  135. : Container(
  136. margin: EdgeInsets.only(top: 40),
  137. child: MaterialButton(
  138. minWidth: 220,
  139. elevation: 0,
  140. highlightElevation: 0,
  141. color: PRIMARY_COLOR,
  142. child: Text(
  143. '立即签到',
  144. style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
  145. ),
  146. onPressed: () {
  147. checkin();
  148. },
  149. ),
  150. )
  151. ],
  152. ),
  153. );
  154. }
  155. Widget item(CheckinConfig config) {
  156. String weekDay = config.weekDay;
  157. String icon;
  158. String name;
  159. if (config.moneyCoin != null) {
  160. icon = 'images/icon_jinbi_qiandao.png';
  161. name = config.moneyCoin.toString() + '金币';
  162. } else if (config.pointsRatio != null) {
  163. icon = 'images/qiandao_icon_jiacheng.png';
  164. name = '加成卡';
  165. } else if (config.minPoints != null) {
  166. icon = 'images/icon_baodi_03.png';
  167. name = '保底卡';
  168. } else if (config.probability != null) {
  169. icon = 'images/qiandao_icon_gailv.png';
  170. name = '概率卡';
  171. }
  172. int checked = config.checked;
  173. List<Widget> list = [
  174. Container(
  175. decoration: BoxDecoration(
  176. color: Color(0xFF253051),
  177. border: Border.all(width: 1, color: PRIMARY_COLOR),
  178. borderRadius: BorderRadius.circular(22),
  179. ),
  180. ),
  181. Center(
  182. child: Image.asset(
  183. icon,
  184. width: 33,
  185. ),
  186. ),
  187. ];
  188. if (checked == 1) {
  189. list.add(Center(
  190. child: Image.asset(
  191. 'images/icon_yiqiandao.png',
  192. ),
  193. ));
  194. } else if (checked == 2) {
  195. list.add(Center(
  196. child: Container(
  197. decoration: BoxDecoration(
  198. color: Color(0xFF4f5c87),
  199. border: Border.all(width: 1, color: Color(0xFF4f5c87)),
  200. borderRadius: BorderRadius.circular(22),
  201. ),
  202. child: Center(
  203. child: Text(
  204. '未签到',
  205. style: TextStyle(color: Colors.white, fontSize: 10),
  206. ),
  207. ),
  208. ),
  209. ));
  210. }
  211. return Container(
  212. width: 76,
  213. child: Column(
  214. children: <Widget>[
  215. Container(
  216. width: 44,
  217. height: 44,
  218. child: Stack(
  219. children: list,
  220. ),
  221. ),
  222. Container(
  223. margin: EdgeInsets.only(top: 6),
  224. child: Text(
  225. weekDay,
  226. style: TextStyle(color: Colors.white, fontSize: 14),
  227. ),
  228. ),
  229. Container(
  230. margin: EdgeInsets.only(top: 2),
  231. child: Text(
  232. name,
  233. style: TextStyle(
  234. color: PRIMARY_COLOR,
  235. fontSize: 12,
  236. ),
  237. ),
  238. )
  239. ],
  240. ),
  241. );
  242. }
  243. }