HomeDrawer.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import 'package:flutter/material.dart';
  2. import 'package:redux/redux.dart';
  3. import 'package:flutter_redux/flutter_redux.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import '../redux/AppState.dart';
  6. import '../model/UserInfo.dart';
  7. import '../pages/MyWallet.dart';
  8. import '../pages/BindGame.dart';
  9. import '../pages/RecordList.dart';
  10. import '../net/HttpManager.dart';
  11. import '../net/Result.dart';
  12. import '../redux/UserRedux.dart';
  13. import '../pages/UserChange.dart';
  14. import '../pages/RoomCardList.dart';
  15. import '../pages/MyTeam.dart';
  16. import '../pages/MyCode.dart';
  17. class HomeDrawer extends StatefulWidget {
  18. @override
  19. HomeDrawerState createState() => HomeDrawerState();
  20. }
  21. class HomeDrawerState extends State<HomeDrawer> {
  22. Future<void> getUserInfo() async {
  23. Result res = await HttpManager.get('userInfo/getUserInfo');
  24. if (res.success) {
  25. print(res.data);
  26. StoreProvider.of<AppState>(context)
  27. .dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
  28. } else {}
  29. }
  30. @override
  31. void initState() {
  32. super.initState();
  33. Future.delayed(Duration.zero, () => getUserInfo());
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return StoreConnector<AppState, UserInfo>(
  38. converter: (Store store) => store.state.userInfo,
  39. builder: (context, userInfo) {
  40. return Drawer(
  41. child: Container(
  42. // decoration: BoxDecoration(
  43. // gradient: LinearGradient(
  44. // begin: Alignment.bottomRight,
  45. // colors: [Color(0xFF3D3E6C), Color(0xFF626C85)],
  46. // )),
  47. color: Color(0xFF3A3E61),
  48. child: Column(
  49. children: <Widget>[
  50. Container(
  51. height: 210,
  52. decoration: BoxDecoration(color: Color(0x4D000000)),
  53. child: SafeArea(
  54. child: Row(
  55. mainAxisAlignment: MainAxisAlignment.center,
  56. children: <Widget>[
  57. ClipOval(
  58. child: InkWell(
  59. child: Image.network(
  60. userInfo.icon,
  61. width: 86,
  62. height: 86,
  63. fit: BoxFit.cover,
  64. ),
  65. onTap: () {
  66. Navigator.push(
  67. context,
  68. CupertinoPageRoute(
  69. builder: (context) => UserChange()));
  70. },
  71. ),
  72. ),
  73. Container(
  74. margin: EdgeInsets.only(left: 16),
  75. child: Column(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. crossAxisAlignment: CrossAxisAlignment.start,
  78. children: <Widget>[
  79. Text(
  80. userInfo.nickname,
  81. style: TextStyle(
  82. fontSize: 27,
  83. color: Colors.white,
  84. fontWeight: FontWeight.w700),
  85. ),
  86. Row(
  87. mainAxisAlignment: MainAxisAlignment.center,
  88. children: <Widget>[
  89. Container(
  90. margin: EdgeInsets.only(right: 4),
  91. child: SizedBox(
  92. width: 20,
  93. height: 20,
  94. child: Image.asset(
  95. 'images/icon_jinbi_da_bai.png'),
  96. ),
  97. ),
  98. Text(
  99. userInfo.moneyCoin.toString(),
  100. style: TextStyle(
  101. fontSize: 16,
  102. color: Colors.white,
  103. fontWeight: FontWeight.w700),
  104. )
  105. ],
  106. ),
  107. ],
  108. ),
  109. )
  110. ],
  111. ),
  112. ),
  113. ),
  114. Expanded(
  115. flex: 1,
  116. child: Container(
  117. padding: EdgeInsets.only(top: 10),
  118. child: Column(
  119. children: <Widget>[
  120. DrawerMenu(
  121. 'images/icon_qianbao.png',
  122. '我的钱包',
  123. onTap: () {
  124. Navigator.push(
  125. context,
  126. CupertinoPageRoute(
  127. builder: (context) => MyWallet()));
  128. },
  129. ),
  130. Divder(),
  131. DrawerMenu(
  132. 'images/icon_fangka.png',
  133. '房卡人数',
  134. tipValue: userInfo.houseCard,
  135. onTap: () {
  136. Navigator.push(
  137. context,
  138. CupertinoPageRoute(
  139. builder: (context) => RoomCardList()));
  140. },
  141. ),
  142. Divder(),
  143. DrawerMenu('images/icon_zhanji.png', '我的赛事', onTap: () {
  144. Navigator.push(
  145. context,
  146. CupertinoPageRoute(
  147. builder: (context) => RecordList()));
  148. }),
  149. Divder(),
  150. DrawerMenu(
  151. 'images/icon_bangding.png',
  152. '游戏绑定',
  153. onTap: () {
  154. Navigator.push(
  155. context,
  156. CupertinoPageRoute(
  157. builder: (context) => BindGame()));
  158. },
  159. ),
  160. Divder(),
  161. DrawerMenu(
  162. 'images/icon_tuandui.png',
  163. '我的团队',
  164. onTap: () {
  165. Navigator.push(
  166. context,
  167. CupertinoPageRoute(
  168. builder: (context) => MyTeam()));
  169. },
  170. ),
  171. Divder(),
  172. DrawerMenu(
  173. 'images/icon_tuiguangma.png',
  174. '我的推广码',
  175. onTap: () {
  176. Navigator.push(
  177. context,
  178. CupertinoPageRoute(
  179. builder: (context) => MyCode()));
  180. },
  181. )
  182. ],
  183. ),
  184. ),
  185. )
  186. ],
  187. ),
  188. ));
  189. },
  190. );
  191. }
  192. }
  193. typedef void OnDrawerMenuTap();
  194. class Divder extends StatelessWidget {
  195. @override
  196. Widget build(BuildContext context) {
  197. return Container(
  198. height: 1,
  199. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  200. child: Container(
  201. decoration: BoxDecoration(color: Color(0x2E000000)),
  202. ),
  203. );
  204. }
  205. }
  206. class DrawerMenu extends StatelessWidget {
  207. final String icon;
  208. final String title;
  209. final OnDrawerMenuTap onTap;
  210. final num tipValue;
  211. DrawerMenu(this.icon, this.title, {this.onTap, this.tipValue});
  212. @override
  213. Widget build(BuildContext context) {
  214. return Container(
  215. height: 60,
  216. padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
  217. child: GestureDetector(
  218. onTap: onTap,
  219. child: Row(
  220. children: <Widget>[
  221. Image.asset(icon),
  222. Expanded(
  223. flex: 1,
  224. child: Container(
  225. margin: EdgeInsets.only(left: 16),
  226. child: Text(
  227. title,
  228. style: TextStyle(
  229. color: Colors.white,
  230. fontSize: 15,
  231. fontWeight: FontWeight.w700),
  232. ),
  233. ),
  234. ),
  235. tipValue != null
  236. ? Text(
  237. tipValue.toString(),
  238. style: TextStyle(fontSize: 13, color: Color(0xFFFFB726)),
  239. )
  240. : Container(),
  241. Image.asset('images/icon_inter.png')
  242. ],
  243. ),
  244. ),
  245. );
  246. }
  247. }