BindGame.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. import 'dart:ui';
  4. import '../styles/totast.dart';
  5. import 'package:flutter_redux/flutter_redux.dart';
  6. import '../redux/AppState.dart';
  7. import '../net/HttpManager.dart';
  8. import '../net/Result.dart';
  9. import '../model/BindGameInfo.dart';
  10. import '../widget/LinearButton.dart';
  11. class BindGame extends StatefulWidget {
  12. @override
  13. BindGameState createState() => BindGameState();
  14. }
  15. class BindGameState extends State<BindGame> {
  16. String bindName = '';
  17. bool isBind = false;
  18. BindGameInfo bindInfo;
  19. Future<void> getBindInfo() async {
  20. Toast.show(context, '加载中', -1, 'loading');
  21. Result res = await HttpManager.get('bindGame/all', data: {
  22. 'gameId': 1,
  23. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id
  24. });
  25. Toast.hide();
  26. if (res.success) {
  27. if (res.data.length > 0) {
  28. setState(() {
  29. isBind = true;
  30. bindInfo = BindGameInfo.fromJson(res.data[0]);
  31. });
  32. } else {
  33. setState(() {
  34. isBind = false;
  35. });
  36. }
  37. }
  38. }
  39. @override
  40. void initState() {
  41. super.initState();
  42. Future.delayed(Duration.zero, () {
  43. getBindInfo();
  44. });
  45. }
  46. Future<void> bindEvent() async {
  47. if (bindName == '') {
  48. Toast.show(context, '请输入和平精英游戏编号', 1500, 'info');
  49. return;
  50. }
  51. Toast.show(context, '加载中', -1, 'loading');
  52. Result res = await HttpManager.post('bindGame/save', data: {
  53. 'gameId': 1,
  54. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  55. 'nickName': bindName
  56. });
  57. Toast.hide();
  58. if (res.success) {
  59. Toast.show(context, '绑定成功', 1000, 'success');
  60. getBindInfo();
  61. } else {}
  62. }
  63. Future<void> cancelBind() async {
  64. Toast.show(context, '加载中', -1, 'loading');
  65. final res =
  66. await HttpManager.post('bindGame/del', data: {'id': bindInfo.id});
  67. Toast.hide();
  68. if (res.success) {
  69. Toast.show(context, '解绑成功', 1000, 'success');
  70. getBindInfo();
  71. } else {}
  72. }
  73. @override
  74. Widget build(BuildContext context) {
  75. return Scaffold(
  76. appBar: AppBar(
  77. // backgroundColor: PRIMARY_COLOR,
  78. title: Text('绑定账号'),
  79. centerTitle: true,
  80. elevation: 0,
  81. ),
  82. body: SingleChildScrollView(
  83. child: Container(
  84. color: BG_SUB_COLOR,
  85. padding: EdgeInsets.all(15),
  86. child: Column(
  87. children: <Widget>[
  88. Container(
  89. height: 220,
  90. width: double.infinity,
  91. // padding: EdgeInsets.symmetric(vertical: 15, horizontal: 34),
  92. decoration: BoxDecoration(
  93. image: DecorationImage(
  94. image: AssetImage('images/img_chijizhanchang.png'),
  95. fit: BoxFit.cover)),
  96. child: Column(
  97. mainAxisAlignment: MainAxisAlignment.end,
  98. children: _bindWidegt(),
  99. ),
  100. ),
  101. Container(
  102. height: 20,
  103. ),
  104. Text('游戏编号位置',style:TextStyle(color:Colors.white,fontSize:14)),
  105. Container(
  106. height: 10,
  107. ),
  108. Image.asset('images/bangding_img_01.png'),
  109. Container(
  110. height: 10,
  111. ),
  112. Image.asset('images/bangding_img_02.png')
  113. ],
  114. ),
  115. ),
  116. ));
  117. }
  118. List<Widget> _bindWidegt() {
  119. List<Widget> widgetList = [];
  120. if (isBind) {
  121. widgetList.add(Container(
  122. height: 78,
  123. padding: EdgeInsets.all(15),
  124. decoration: BoxDecoration(
  125. gradient: LinearGradient(
  126. colors: [Color(0xFF464B6A), Color(0xFF35395E)],
  127. begin: Alignment.topCenter,
  128. end: Alignment.bottomCenter)),
  129. child: Row(
  130. children: <Widget>[
  131. Image.network(bindInfo.gameInfo.icon, width: 48),
  132. Container(
  133. width: 10,
  134. ),
  135. Expanded(
  136. flex: 1,
  137. child: Column(
  138. mainAxisAlignment: MainAxisAlignment.center,
  139. crossAxisAlignment: CrossAxisAlignment.start,
  140. children: <Widget>[
  141. Text(bindInfo.gameInfo.gameName,
  142. style: TextStyle(color: Colors.white, fontSize: 14)),
  143. Container(
  144. height: 5,
  145. ),
  146. Row(
  147. children: <Widget>[
  148. Text(
  149. '已绑定',
  150. style: TextStyle(
  151. color: Color(0xFF727785),
  152. fontSize: 13,
  153. fontWeight: FontWeight.w500),
  154. ),
  155. Container(
  156. width: 10,
  157. ),
  158. Text(
  159. bindInfo.nickName,
  160. style: TextStyle(
  161. color: Colors.white,
  162. fontSize: 13,
  163. fontWeight: FontWeight.w500),
  164. )
  165. ],
  166. )
  167. ],
  168. )),
  169. Container(
  170. width: 50,
  171. height: 30,
  172. child: OutlineButton(
  173. padding: EdgeInsets.all(0),
  174. borderSide: BorderSide(color: Theme.of(context).primaryColor, width: 1),
  175. textColor: Theme.of(context).primaryColor,
  176. highlightColor: Color(0xFF16161C),
  177. child: Text('解绑'),
  178. onPressed: () => cancelBind(),
  179. ))
  180. ],
  181. ),
  182. ));
  183. } else {
  184. widgetList = [
  185. Container(
  186. margin: EdgeInsets.only(bottom: 10, left: 45, right: 45),
  187. decoration: BoxDecoration(
  188. borderRadius: BorderRadius.all(Radius.circular(2)),
  189. color: Colors.white,
  190. ),
  191. child: TextField(
  192. style: TextStyle(
  193. color: Color(0xFFFFC30F),
  194. fontWeight: FontWeight.w500,
  195. ),
  196. textAlign: TextAlign.center,
  197. decoration: InputDecoration(
  198. hintText: '请输入刺激战场游戏昵称',
  199. border: InputBorder.none,
  200. hintStyle: TextStyle(fontSize: 12, color: Color(0xFF727785)),
  201. contentPadding: const EdgeInsets.symmetric(vertical:10.0),
  202. ),
  203. onChanged: (value) {
  204. setState(() {
  205. bindName = value;
  206. });
  207. },
  208. ),
  209. ),
  210. Container(
  211. margin: EdgeInsets.only(left: 45, right: 45, bottom: 15),
  212. width: double.infinity,
  213. child: LinearButton(
  214. btntext: '绑定角色',
  215. btnHeight: 36.0,
  216. onTapHomeMenu: () => bindEvent(),
  217. ))
  218. ];
  219. }
  220. return widgetList;
  221. }
  222. }