BindGame.dart 7.2 KB

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