BindGame.dart 6.1 KB

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