HomeDrawer.dart 6.0 KB

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