HomeDrawer.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 '../model/UserInfo.dart';
  13. import '../redux/AppState.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).dispatch({"action": Actions.updateUser, "user": res.data});
  23. } else {}
  24. }
  25. @override
  26. void initState() {
  27. // TODO: implement initState
  28. super.initState();
  29. Future.delayed(Duration(milliseconds: 100),()=>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: Image.network(
  54. userInfo.icon,
  55. width: 86,
  56. height: 86,
  57. fit: BoxFit.cover,
  58. ),
  59. ),
  60. Container(
  61. margin: EdgeInsets.only(left: 16),
  62. child: Column(
  63. mainAxisAlignment: MainAxisAlignment.center,
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: <Widget>[
  66. Text(
  67. userInfo.nickname,
  68. style: TextStyle(
  69. fontSize: 27,
  70. color: Colors.white,
  71. fontWeight: FontWeight.w700),
  72. ),
  73. Row(
  74. mainAxisAlignment: MainAxisAlignment.center,
  75. children: <Widget>[
  76. Container(
  77. margin: EdgeInsets.only(right: 4),
  78. child: SizedBox(
  79. width: 20,
  80. height: 20,
  81. child: Image.asset(
  82. "images/icon_jinbi_da_bai.png"),
  83. ),
  84. ),
  85. Text(
  86. userInfo.moneyCoin.toString(),
  87. style: TextStyle(
  88. fontSize: 16,
  89. color: Colors.white,
  90. fontWeight: FontWeight.w700),
  91. )
  92. ],
  93. ),
  94. ],
  95. ),
  96. )
  97. ],
  98. ),
  99. ),
  100. ),
  101. Expanded(
  102. flex: 1,
  103. child: Container(
  104. padding: EdgeInsets.only(top: 10),
  105. child: Column(
  106. children: <Widget>[
  107. DrawerMenu(
  108. "images/icon_qianbao.png",
  109. "我的钱包",
  110. onTap: () {
  111. Navigator.push(
  112. context,
  113. new CupertinoPageRoute(
  114. builder: (context) => new MyWallet()));
  115. },
  116. ),
  117. Divder(),
  118. DrawerMenu("images/icon_zhanji.png", "我的战绩", onTap: () {
  119. Navigator.push(
  120. context,
  121. new CupertinoPageRoute(
  122. builder: (context) => new RecordList()));
  123. }),
  124. Divder(),
  125. DrawerMenu(
  126. "images/icon_bangding.png",
  127. "游戏绑定",
  128. onTap: () {
  129. Navigator.push(
  130. context,
  131. new CupertinoPageRoute(
  132. builder: (context) => new BindGame()));
  133. },
  134. )
  135. ],
  136. ),
  137. ),
  138. )
  139. ],
  140. ),
  141. ));
  142. },
  143. );
  144. }
  145. }
  146. typedef void OnDrawerMenuTap();
  147. class Divder extends StatelessWidget {
  148. @override
  149. Widget build(BuildContext context) {
  150. return Container(
  151. height: 1,
  152. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  153. child: Container(
  154. decoration: BoxDecoration(color: Color(0x2E000000)),
  155. ),
  156. );
  157. }
  158. }
  159. class DrawerMenu extends StatelessWidget {
  160. final String icon;
  161. final String title;
  162. final OnDrawerMenuTap onTap;
  163. DrawerMenu(this.icon, this.title, {this.onTap});
  164. @override
  165. Widget build(BuildContext context) {
  166. return Container(
  167. height: 60,
  168. padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
  169. child: GestureDetector(
  170. onTap: onTap,
  171. child: Row(
  172. children: <Widget>[
  173. Image.asset(icon),
  174. Expanded(
  175. flex: 1,
  176. child: Container(
  177. margin: EdgeInsets.only(left: 16),
  178. child: Text(
  179. title,
  180. style: TextStyle(
  181. color: Colors.white,
  182. fontSize: 15,
  183. fontWeight: FontWeight.w700),
  184. ),
  185. ),
  186. ),
  187. Image.asset("images/icon_inter.png")
  188. ],
  189. ),
  190. ),
  191. );
  192. }
  193. }