TipInfo.dart 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'dart:ui';
  5. import '../styles/totast.dart';
  6. import '../model/SystemNotice.dart';
  7. import '../net/HttpManager.dart';
  8. import '../net/Result.dart';
  9. import '../model/HouseInfo.dart';
  10. import '../model/GameInfo.dart';
  11. import '../pages/RoomInfo.dart';
  12. class TipInfo extends StatefulWidget {
  13. TipInfo({Key key, this.tipId}) : super(key: key);
  14. final int tipId;
  15. @override
  16. TipInfoState createState() => TipInfoState();
  17. }
  18. class TipInfoState extends State<TipInfo> {
  19. SystemNotice tipInfo = SystemNotice.fromJson(
  20. {'content': '', "createTime": DateTime.now().microsecondsSinceEpoch});
  21. HouseInfo houseInfo;
  22. getInfo() async {
  23. Toast.show(context, '加载中', -1, 'loading');
  24. Result res = await HttpManager.get("systemNotice/getOne",
  25. data: {'id': widget.tipId});
  26. Toast.hide();
  27. if (res.success) {
  28. setState(() {
  29. tipInfo = SystemNotice.fromJson(res.data);
  30. });
  31. }
  32. if (tipInfo.statusFlag == 0 && tipInfo.typeFlag != 2) {
  33. HttpManager.post("systemNotice/update",
  34. data: {'id': tipInfo.id, "statusFlag": 1});
  35. }
  36. Result res2 = await HttpManager.get("houseInfo/getOne",
  37. data: {'id': tipInfo.houseId});
  38. if (res2.success) {
  39. setState(() {
  40. houseInfo = HouseInfo.fromJson(res2.data);
  41. });
  42. }
  43. }
  44. void updateHousInfo() {}
  45. @override
  46. void initState() {
  47. super.initState();
  48. Future.delayed(Duration(milliseconds: 100), () => getInfo());
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. int type = tipInfo.typeFlag != null ? tipInfo.typeFlag : 0;
  53. int status = tipInfo.statusFlag ?? 0;
  54. GameInfo gameInfo;
  55. if (tipInfo.gameInfo != null) {
  56. gameInfo = tipInfo.gameInfo;
  57. }
  58. return new WillPopScope(
  59. child: Scaffold(
  60. appBar: AppBar(
  61. backgroundColor: PRIMARY_COLOR,
  62. title: Text('通知详情'),
  63. centerTitle: true,
  64. elevation: 0,
  65. ),
  66. body: Container(
  67. color: Color(0xFF2B2B42),
  68. width: double.infinity,
  69. height: double.infinity,
  70. child: Column(
  71. children: <Widget>[
  72. Padding(
  73. padding: EdgeInsets.only(left: 15, right: 45),
  74. child: Column(
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. children: <Widget>[
  77. Padding(
  78. padding: EdgeInsets.symmetric(vertical: 12),
  79. child: Text(
  80. readTimestamp(
  81. tipInfo.createTime, 'yyyy.MM.dd HH:mm:ss'),
  82. style:
  83. TextStyle(color: Colors.white24, fontSize: 13)),
  84. ),
  85. Container(
  86. height: 1,
  87. color: Colors.black26,
  88. ),
  89. Padding(
  90. padding: EdgeInsets.only(top: 10, bottom: 17),
  91. child: Text(
  92. tipInfo.content,
  93. style: TextStyle(color: Colors.white, fontSize: 14),
  94. ),
  95. )
  96. ],
  97. ),
  98. ),
  99. houseInfo != null
  100. ? houseItem(roomInfo: houseInfo, gameInfo: gameInfo)
  101. : Container(),
  102. type == 2 && status == 0
  103. ? Container(
  104. width: double.infinity,
  105. height: 48,
  106. padding: EdgeInsets.symmetric(horizontal: 15),
  107. child: RaisedButton(
  108. textColor: Colors.white,
  109. child: Text('立即领取'),
  110. onPressed: () async {
  111. Toast.show(context, '加载中', -1, 'loading');
  112. Result res = await HttpManager.post(
  113. "playerInfo/receive",
  114. data: {"id": tipInfo.playerId});
  115. Toast.hide();
  116. print(res.data);
  117. if (res.success) {
  118. Toast.show(context, '领取成功', 1000, 'success');
  119. Future.delayed(Duration(milliseconds: 1000),
  120. () => getInfo());
  121. } else {
  122. Toast.show(context, res.error, 1000, 'info');
  123. }
  124. },
  125. ),
  126. )
  127. : Container()
  128. ],
  129. ),
  130. )),
  131. onWillPop: () {
  132. Navigator.of(context).pop(true);
  133. Toast.hide();
  134. return Future.value(false);
  135. },
  136. );
  137. }
  138. }
  139. class houseItem extends StatelessWidget {
  140. houseItem({Key key, this.roomInfo, this.gameInfo}) : super(key: key);
  141. final HouseInfo roomInfo;
  142. final GameInfo gameInfo;
  143. @override
  144. Widget build(BuildContext context) {
  145. return Container(
  146. margin: EdgeInsets.only(bottom: 50),
  147. decoration: BoxDecoration(
  148. gradient: LinearGradient(
  149. colors: [Color(0xFF3F4261), Color(0xFF323456)],
  150. begin: Alignment.topCenter,
  151. end: Alignment.bottomCenter,
  152. ),
  153. border: Border(bottom: BorderSide(color: Colors.black, width: 1))),
  154. child: Material(
  155. color: Colors.transparent,
  156. child: InkWell(
  157. child: Padding(
  158. padding: EdgeInsets.all(15),
  159. child: Row(
  160. children: <Widget>[
  161. Image.network(
  162. gameInfo.icon,
  163. width: 48,
  164. height: 48,
  165. ),
  166. Container(
  167. width: 10,
  168. ),
  169. Expanded(
  170. flex: 1,
  171. child: Column(
  172. crossAxisAlignment: CrossAxisAlignment.start,
  173. children: <Widget>[
  174. Row(
  175. children: <Widget>[
  176. LimitedBox(
  177. maxWidth: 170,
  178. child: Text(
  179. roomInfo.houseName,
  180. style: TextStyle(
  181. color: Colors.white,
  182. fontSize: 14,
  183. fontWeight: FontWeight.w500),
  184. maxLines: 1,
  185. overflow: TextOverflow.ellipsis,
  186. ),
  187. ),
  188. Container(
  189. margin: EdgeInsets.only(left: 6),
  190. child: Image.network(roomInfo.houseLevel.icon,
  191. width: 14),
  192. ),
  193. Container(
  194. margin: EdgeInsets.only(left: 1),
  195. child: Text(
  196. roomInfo.houseLevel.levelName,
  197. style: TextStyle(
  198. color: Color(0xFFF9D881), fontSize: 9),
  199. )),
  200. ],
  201. ),
  202. Text(
  203. roomInfo.houseAbstract,
  204. style: TextStyle(
  205. fontSize: 12,
  206. fontWeight: FontWeight.w400,
  207. color: Color(0xFF9BA0AE)),
  208. maxLines: 2,
  209. overflow: TextOverflow.ellipsis,
  210. )
  211. ],
  212. ),
  213. ),
  214. Row(
  215. mainAxisAlignment: MainAxisAlignment.center,
  216. children: <Widget>[
  217. Image.asset('images/icon_renshu.png', width: 20),
  218. Text(
  219. (roomInfo.playerNumber != null
  220. ? roomInfo.playerNumber.toString()
  221. : '0') +
  222. '/' +
  223. roomInfo.maxNumber.toString(),
  224. style: TextStyle(
  225. fontSize: 14,
  226. fontWeight: FontWeight.w500,
  227. color: Color(0xFFB1B2C0)),
  228. )
  229. ],
  230. )
  231. ],
  232. ),
  233. ),
  234. onTap: () {
  235. Navigator.push(
  236. context,
  237. new CupertinoPageRoute(
  238. builder: (context) =>
  239. new RoomInfo(roomId: roomInfo.id.toString())));
  240. },
  241. ),
  242. ),
  243. );
  244. }
  245. }