HomeDrawer.dart 6.2 KB

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