HomeDrawer.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. class HomeDrawer extends StatefulWidget {
  15. @override
  16. HomeDrawerState createState() => HomeDrawerState();
  17. }
  18. class HomeDrawerState extends State<HomeDrawer> {
  19. void getUserInfo() async {
  20. Result res = await HttpManager.get("userInfo/getUserInfo");
  21. if (res.success) {
  22. StoreProvider.of<AppState>(context)
  23. .dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
  24. } else {}
  25. }
  26. @override
  27. void initState() {
  28. super.initState();
  29. Future.delayed(Duration.zero, () => getUserInfo());
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return StoreConnector<AppState, UserInfo>(
  34. converter: (Store store) => store.state.userInfo,
  35. builder: (context, userInfo) {
  36. return Drawer(
  37. child: Container(
  38. decoration: BoxDecoration(
  39. gradient: LinearGradient(
  40. begin: Alignment.bottomRight,
  41. colors: [Color(0xFF3D3E6C), Color(0xFF626C85)],
  42. )),
  43. child: Column(
  44. children: <Widget>[
  45. Container(
  46. height: 210,
  47. decoration: BoxDecoration(color: Color(0x4D000000)),
  48. child: SafeArea(
  49. child: Row(
  50. mainAxisAlignment: MainAxisAlignment.center,
  51. children: <Widget>[
  52. ClipOval(
  53. child: InkWell(
  54. child: Image.network(
  55. userInfo.icon,
  56. width: 86,
  57. height: 86,
  58. fit: BoxFit.cover,
  59. ),
  60. onTap: () {
  61. Navigator.push(
  62. context,
  63. new CupertinoPageRoute(
  64. builder: (context) => new UserChange()));
  65. },
  66. ),
  67. ),
  68. Container(
  69. margin: EdgeInsets.only(left: 16),
  70. child: Column(
  71. mainAxisAlignment: MainAxisAlignment.center,
  72. crossAxisAlignment: CrossAxisAlignment.start,
  73. children: <Widget>[
  74. Text(
  75. userInfo.nickname,
  76. style: TextStyle(
  77. fontSize: 27,
  78. color: Colors.white,
  79. fontWeight: FontWeight.w700),
  80. ),
  81. Row(
  82. mainAxisAlignment: MainAxisAlignment.center,
  83. children: <Widget>[
  84. Container(
  85. margin: EdgeInsets.only(right: 4),
  86. child: SizedBox(
  87. width: 20,
  88. height: 20,
  89. child: Image.asset(
  90. "images/icon_jinbi_da_bai.png"),
  91. ),
  92. ),
  93. Text(
  94. userInfo.moneyCoin.toString(),
  95. style: TextStyle(
  96. fontSize: 16,
  97. color: Colors.white,
  98. fontWeight: FontWeight.w700),
  99. )
  100. ],
  101. ),
  102. ],
  103. ),
  104. )
  105. ],
  106. ),
  107. ),
  108. ),
  109. Expanded(
  110. flex: 1,
  111. child: Container(
  112. padding: EdgeInsets.only(top: 10),
  113. child: Column(
  114. children: <Widget>[
  115. DrawerMenu(
  116. "images/icon_qianbao.png",
  117. "我的钱包",
  118. onTap: () {
  119. Navigator.push(
  120. context,
  121. new CupertinoPageRoute(
  122. builder: (context) => new MyWallet()));
  123. },
  124. ),
  125. Divder(),
  126. DrawerMenu("images/icon_zhanji.png", "我的战绩", onTap: () {
  127. Navigator.push(
  128. context,
  129. new CupertinoPageRoute(
  130. builder: (context) => new RecordList()));
  131. }),
  132. Divder(),
  133. DrawerMenu(
  134. "images/icon_bangding.png",
  135. "游戏绑定",
  136. onTap: () {
  137. Navigator.push(
  138. context,
  139. new CupertinoPageRoute(
  140. builder: (context) => new BindGame()));
  141. },
  142. ),
  143. // Divder(),
  144. // DrawerMenu('images/home_icon_shezhi.png', '个人设置',onTap: (){
  145. // Navigator.push(context, new CupertinoPageRoute(builder: (context) => new Setting()));
  146. // },)
  147. ],
  148. ),
  149. ),
  150. )
  151. ],
  152. ),
  153. ));
  154. },
  155. );
  156. }
  157. }
  158. typedef void OnDrawerMenuTap();
  159. class Divder extends StatelessWidget {
  160. @override
  161. Widget build(BuildContext context) {
  162. return Container(
  163. height: 1,
  164. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  165. child: Container(
  166. decoration: BoxDecoration(color: Color(0x2E000000)),
  167. ),
  168. );
  169. }
  170. }
  171. class DrawerMenu extends StatelessWidget {
  172. final String icon;
  173. final String title;
  174. final OnDrawerMenuTap onTap;
  175. DrawerMenu(this.icon, this.title, {this.onTap});
  176. @override
  177. Widget build(BuildContext context) {
  178. return Container(
  179. height: 60,
  180. padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
  181. child: GestureDetector(
  182. onTap: onTap,
  183. child: Row(
  184. children: <Widget>[
  185. Image.asset(icon),
  186. Expanded(
  187. flex: 1,
  188. child: Container(
  189. margin: EdgeInsets.only(left: 16),
  190. child: Text(
  191. title,
  192. style: TextStyle(
  193. color: Colors.white,
  194. fontSize: 15,
  195. fontWeight: FontWeight.w700),
  196. ),
  197. ),
  198. ),
  199. Image.asset("images/icon_inter.png")
  200. ],
  201. ),
  202. ),
  203. );
  204. }
  205. }