HomeDrawer.dart 8.8 KB

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