HomeDrawer.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:redux/redux.dart';
  4. import 'package:flutter_redux/flutter_redux.dart';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:ttdj_plugin/ttdj_plugin.dart';
  7. import '../redux/AppState.dart';
  8. import '../model/UserInfo.dart';
  9. import '../pages/MyWallet.dart';
  10. import '../pages/BindGame.dart';
  11. import '../pages/RecordList.dart';
  12. import '../net/HttpManager.dart';
  13. import '../net/Result.dart';
  14. import '../redux/UserRedux.dart';
  15. import '../pages/UserChange.dart';
  16. import '../styles/colors.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. StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
  26. } else {}
  27. }
  28. @override
  29. void initState() {
  30. super.initState();
  31. Future.delayed(Duration.zero, () => getUserInfo());
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return StoreConnector<AppState, UserInfo>(
  36. converter: (Store store) => store.state.userInfo,
  37. builder: (context, userInfo) {
  38. return Drawer(
  39. child: Container(
  40. color: SUB_COLOR,
  41. child: Column(
  42. children: <Widget>[
  43. Container(
  44. height: 210,
  45. decoration: BoxDecoration(color: Color(0x4D000000)),
  46. child: SafeArea(
  47. child: Row(
  48. mainAxisAlignment: MainAxisAlignment.center,
  49. children: <Widget>[
  50. ClipOval(
  51. child: InkWell(
  52. child: CachedNetworkImage(
  53. imageUrl: userInfo.icon,
  54. width: 86,
  55. height: 86,
  56. fit: BoxFit.cover,
  57. ),
  58. onTap: () {
  59. Navigator.push(context, CupertinoPageRoute(builder: (context) => UserChange()));
  60. },
  61. ),
  62. ),
  63. Container(
  64. margin: EdgeInsets.only(left: 16),
  65. child: Column(
  66. mainAxisAlignment: MainAxisAlignment.center,
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. children: <Widget>[
  69. Text(
  70. userInfo.nickname,
  71. style: TextStyle(fontSize: 27, color: Colors.white, fontWeight: FontWeight.normal),
  72. ),
  73. Row(
  74. mainAxisAlignment: MainAxisAlignment.center,
  75. crossAxisAlignment: CrossAxisAlignment.center,
  76. children: <Widget>[
  77. Container(
  78. margin: EdgeInsets.only(right: 4),
  79. child: SizedBox(
  80. width: 20,
  81. height: 20,
  82. child: Image.asset('images/icon_jiner.png'),
  83. ),
  84. ),
  85. Text(
  86. userInfo.moneyCoin.toString(),
  87. style: TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.normal),
  88. )
  89. ],
  90. ),
  91. ],
  92. ),
  93. )
  94. ],
  95. ),
  96. ),
  97. ),
  98. Expanded(
  99. flex: 1,
  100. child: Container(
  101. padding: EdgeInsets.only(top: 10),
  102. child: Column(
  103. children: <Widget>[
  104. // DrawerMenu(
  105. // 'images/icon_qianbao.png',
  106. // '我的钱包',
  107. // onTap: () {
  108. // Navigator.push(context, CupertinoPageRoute(builder: (context) => MyWallet()));
  109. // },
  110. // ),
  111. // Divder(),
  112. DrawerMenu('images/icon_zhanji.png', '我的战绩', onTap: () {
  113. Navigator.push(context, CupertinoPageRoute(builder: (context) => RecordList()));
  114. }),
  115. Divder(),
  116. // DrawerMenu(
  117. // 'images/icon_bangding.png',
  118. // '游戏绑定',
  119. // onTap: () {
  120. // Navigator.push(context, CupertinoPageRoute(builder: (context) => BindGame()));
  121. // },
  122. // ),
  123. // Divder(),
  124. DrawerMenu(
  125. 'images/icon_bangding.png',
  126. 'VIP会员',
  127. onTap: () {
  128. TtdjPlugin.init(userInfo.ttdjId, userInfo.token);
  129. TtdjPlugin.gotoVipPage();
  130. },
  131. ),
  132. // Divder(),
  133. // DrawerMenu('images/home_icon_shezhi.png', '个人设置',onTap: (){
  134. // Navigator.push(context, CupertinoPageRoute(builder: (context) => Setting()));
  135. // },)
  136. ],
  137. ),
  138. ),
  139. )
  140. ],
  141. ),
  142. ));
  143. },
  144. );
  145. }
  146. }
  147. typedef void OnDrawerMenuTap();
  148. class Divder extends StatelessWidget {
  149. @override
  150. Widget build(BuildContext context) {
  151. return Container(
  152. height: 1,
  153. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  154. child: Container(
  155. decoration: BoxDecoration(color: Color(0x2E000000)),
  156. ),
  157. );
  158. }
  159. }
  160. class DrawerMenu extends StatelessWidget {
  161. final String icon;
  162. final String title;
  163. final OnDrawerMenuTap onTap;
  164. DrawerMenu(this.icon, this.title, {this.onTap});
  165. @override
  166. Widget build(BuildContext context) {
  167. return GestureDetector(
  168. onTap: onTap,
  169. child: Container(
  170. height: 60,
  171. padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
  172. child: Row(
  173. children: <Widget>[
  174. Image.asset(icon),
  175. Expanded(
  176. flex: 1,
  177. child: Container(
  178. margin: EdgeInsets.only(left: 16),
  179. child: Text(
  180. title,
  181. style: TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.normal),
  182. ),
  183. ),
  184. ),
  185. Image.asset('images/icon_inter.png')
  186. ],
  187. ),
  188. ),
  189. );
  190. }
  191. }