HomeDrawer.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. Future<void> getUserInfo() async {
  20. Result res = await HttpManager.get('userInfo/getUserInfo');
  21. if (res.success) {
  22. StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
  23. } else {}
  24. }
  25. @override
  26. void initState() {
  27. super.initState();
  28. Future.delayed(Duration.zero, () => getUserInfo());
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return StoreConnector<AppState, UserInfo>(
  33. converter: (Store store) => store.state.userInfo,
  34. builder: (context, userInfo) {
  35. return Drawer(
  36. child: Container(
  37. decoration: BoxDecoration(
  38. gradient: LinearGradient(
  39. begin: Alignment.bottomRight,
  40. colors: [Color(0xFF3D3E6C), Color(0xFF626C85)],
  41. )),
  42. child: Column(
  43. children: <Widget>[
  44. Container(
  45. height: 210,
  46. decoration: BoxDecoration(color: Color(0x4D000000)),
  47. child: SafeArea(
  48. child: Row(
  49. mainAxisAlignment: MainAxisAlignment.center,
  50. children: <Widget>[
  51. ClipOval(
  52. child: InkWell(
  53. child: Image.network(
  54. userInfo.icon,
  55. width: 86,
  56. height: 86,
  57. fit: BoxFit.cover,
  58. ),
  59. onTap: () {
  60. Navigator.push(context, CupertinoPageRoute(builder: (context) => UserChange()));
  61. },
  62. ),
  63. ),
  64. Container(
  65. margin: EdgeInsets.only(left: 16),
  66. child: Column(
  67. mainAxisAlignment: MainAxisAlignment.center,
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. children: <Widget>[
  70. Text(
  71. userInfo.nickname,
  72. style: TextStyle(fontSize: 27, color: Colors.white, fontWeight: FontWeight.w700),
  73. ),
  74. Row(
  75. mainAxisAlignment: MainAxisAlignment.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_jinbi_da_bai.png'),
  83. ),
  84. ),
  85. Text(
  86. userInfo.moneyCoin.toString(),
  87. style: TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700),
  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('images/home_icon_shezhi.png', '个人设置',onTap: (){
  125. // Navigator.push(context, CupertinoPageRoute(builder: (context) => Setting()));
  126. // },)
  127. ],
  128. ),
  129. ),
  130. )
  131. ],
  132. ),
  133. ));
  134. },
  135. );
  136. }
  137. }
  138. typedef void OnDrawerMenuTap();
  139. class Divder extends StatelessWidget {
  140. @override
  141. Widget build(BuildContext context) {
  142. return Container(
  143. height: 1,
  144. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  145. child: Container(
  146. decoration: BoxDecoration(color: Color(0x2E000000)),
  147. ),
  148. );
  149. }
  150. }
  151. class DrawerMenu extends StatelessWidget {
  152. final String icon;
  153. final String title;
  154. final OnDrawerMenuTap onTap;
  155. DrawerMenu(this.icon, this.title, {this.onTap});
  156. @override
  157. Widget build(BuildContext context) {
  158. return Container(
  159. height: 60,
  160. padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
  161. child: GestureDetector(
  162. onTap: onTap,
  163. child: Row(
  164. children: <Widget>[
  165. Image.asset(icon),
  166. Expanded(
  167. flex: 1,
  168. child: Container(
  169. margin: EdgeInsets.only(left: 16),
  170. child: Text(
  171. title,
  172. style: TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.w700),
  173. ),
  174. ),
  175. ),
  176. Image.asset('images/icon_inter.png')
  177. ],
  178. ),
  179. ),
  180. );
  181. }
  182. }