HomeDrawer.dart 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. padding: EdgeInsets.only(left: 35),
  53. decoration: BoxDecoration(color: Color(0x4D000000)),
  54. child: SafeArea(
  55. child: Row(
  56. // mainAxisAlignment: MainAxisAlignment.center,
  57. children: <Widget>[
  58. ClipOval(
  59. child: InkWell(
  60. child: Image.network(
  61. userInfo.icon,
  62. width: 86,
  63. height: 86,
  64. fit: BoxFit.cover,
  65. ),
  66. onTap: () {
  67. Navigator.push(
  68. context,
  69. CupertinoPageRoute(
  70. builder: (context) => UserChange()));
  71. },
  72. ),
  73. ),
  74. Container(
  75. margin: EdgeInsets.only(left: 16),
  76. child: Column(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. crossAxisAlignment: CrossAxisAlignment.start,
  79. children: <Widget>[
  80. Text(
  81. userInfo.nickname,
  82. style: TextStyle(
  83. fontSize: 27,
  84. color: Colors.white,
  85. fontWeight: FontWeight.w700),
  86. ),
  87. Row(
  88. mainAxisAlignment: MainAxisAlignment.center,
  89. children: <Widget>[
  90. Container(
  91. margin: EdgeInsets.only(right: 4),
  92. child: SizedBox(
  93. width: 20,
  94. height: 20,
  95. child: Image.asset(
  96. 'images/icon_menpiao.png'),
  97. ),
  98. ),
  99. Text(
  100. userInfo.moneyTicket.toString(),
  101. style: TextStyle(
  102. fontSize: 16,
  103. color: Colors.white,
  104. fontWeight: FontWeight.w700),
  105. )
  106. ],
  107. ),
  108. ],
  109. ),
  110. )
  111. ],
  112. ),
  113. ),
  114. ),
  115. Expanded(
  116. flex: 1,
  117. child: Container(
  118. padding: EdgeInsets.only(top: 10),
  119. child: Column(
  120. children: <Widget>[
  121. DrawerMenu(
  122. 'images/icon_qianbao.png',
  123. '我的门票',
  124. onTap: () {
  125. Navigator.push(
  126. context,
  127. CupertinoPageRoute(
  128. builder: (context) => MyWallet()));
  129. },
  130. ),
  131. Divder(),
  132. DrawerMenu(
  133. 'images/icon_fangka.png',
  134. '房卡人数',
  135. tipValue: userInfo.houseCard,
  136. onTap: () {
  137. Navigator.push(
  138. context,
  139. CupertinoPageRoute(
  140. builder: (context) => RoomCardList()));
  141. },
  142. ),
  143. Divder(),
  144. DrawerMenu('images/icon_zhanji.png', '我的赛事', onTap: () {
  145. Navigator.push(
  146. context,
  147. CupertinoPageRoute(
  148. builder: (context) => RecordList()));
  149. }),
  150. Divder(),
  151. DrawerMenu(
  152. 'images/icon_bangding.png',
  153. '游戏绑定',
  154. onTap: () {
  155. Navigator.push(
  156. context,
  157. CupertinoPageRoute(
  158. builder: (context) => BindGame()));
  159. },
  160. ),
  161. Divder(),
  162. DrawerMenu(
  163. 'images/icon_tuandui.png',
  164. '我的团队',
  165. onTap: () {
  166. Navigator.push(
  167. context,
  168. CupertinoPageRoute(
  169. builder: (context) => MyTeam()));
  170. },
  171. ),
  172. Divder(),
  173. DrawerMenu(
  174. 'images/icon_tuiguangma.png',
  175. '我的推广码',
  176. onTap: () {
  177. Navigator.push(
  178. context,
  179. CupertinoPageRoute(
  180. builder: (context) => MyCode()));
  181. },
  182. )
  183. ],
  184. ),
  185. ),
  186. )
  187. ],
  188. ),
  189. ));
  190. },
  191. );
  192. }
  193. }
  194. typedef void OnDrawerMenuTap();
  195. class Divder extends StatelessWidget {
  196. @override
  197. Widget build(BuildContext context) {
  198. return Container(
  199. height: 1,
  200. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  201. child: Container(
  202. decoration: BoxDecoration(color: Color(0x2E000000)),
  203. ),
  204. );
  205. }
  206. }
  207. class DrawerMenu extends StatelessWidget {
  208. final String icon;
  209. final String title;
  210. final OnDrawerMenuTap onTap;
  211. final num tipValue;
  212. DrawerMenu(this.icon, this.title, {this.onTap, this.tipValue});
  213. @override
  214. Widget build(BuildContext context) {
  215. return Container(
  216. height: 60,
  217. padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
  218. child: GestureDetector(
  219. onTap: onTap,
  220. child: Row(
  221. children: <Widget>[
  222. Image.asset(icon),
  223. Expanded(
  224. flex: 1,
  225. child: Container(
  226. margin: EdgeInsets.only(left: 16),
  227. child: Text(
  228. title,
  229. style: TextStyle(
  230. color: Colors.white,
  231. fontSize: 15,
  232. fontWeight: FontWeight.w700),
  233. ),
  234. ),
  235. ),
  236. tipValue != null
  237. ? Text(
  238. tipValue.toString(),
  239. style: TextStyle(fontSize: 13, color: Theme.of(context).primaryColor),
  240. )
  241. : Container(),
  242. Image.asset('images/icon_inter.png')
  243. ],
  244. ),
  245. ),
  246. );
  247. }
  248. }