MyWallet.dart 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import '../styles/colors.dart';
  4. import 'package:redux/redux.dart';
  5. import 'package:flutter_redux/flutter_redux.dart';
  6. import '../redux/AppState.dart';
  7. import '../model/UserInfo.dart';
  8. import '../net/HttpManager.dart';
  9. import '../net/Result.dart';
  10. import 'dart:ui';
  11. import '../styles/totast.dart';
  12. import 'Recharge.dart';
  13. class MyWallet extends StatefulWidget {
  14. @override
  15. MyWalletState createState() => MyWalletState();
  16. }
  17. class MyWalletState extends State<MyWallet> {
  18. ScrollController _controller;
  19. List walletList;
  20. bool isShow = false;
  21. num _topHeight;
  22. int currentPage = 1;
  23. bool canNext = true;
  24. Future<void> getWalletPage() async {
  25. Toast.show(context, '加载中', -1, 'loading');
  26. canNext = false;
  27. Result res = await HttpManager.get('memberCoin/page',
  28. data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'currentPage': currentPage, 'pageNumber': 20});
  29. Toast.hide();
  30. if (res.success) {
  31. if (currentPage == 1) {
  32. walletList = [];
  33. }
  34. setState(() {
  35. walletList.addAll(res.data['pp']);
  36. });
  37. if (res.data['page']['totalNumber'] > currentPage) {
  38. canNext = true;
  39. }
  40. } else {}
  41. }
  42. @override
  43. void initState() {
  44. super.initState();
  45. walletList = List<Map>();
  46. Future.delayed(Duration.zero, () {
  47. getWalletPage();
  48. });
  49. _controller = ScrollController();
  50. isShow = false;
  51. _controller.addListener(() {
  52. if (_controller.position.pixels == _controller.position.maxScrollExtent && canNext) {
  53. currentPage++;
  54. getWalletPage();
  55. }
  56. if (_controller.position.pixels >= _topHeight + 82) {
  57. setState(() {
  58. isShow = true;
  59. });
  60. } else {
  61. setState(() {
  62. isShow = false;
  63. });
  64. }
  65. });
  66. }
  67. @override
  68. void dispose() {
  69. super.dispose();
  70. _controller.dispose();
  71. }
  72. @override
  73. Widget build(BuildContext context) {
  74. return StoreConnector<AppState, UserInfo>(
  75. converter: (Store store) => store.state.userInfo,
  76. builder: (context, userInfo) {
  77. return Scaffold(
  78. appBar: AppBar(
  79. title: Text('我的钱包'),
  80. centerTitle: true,
  81. ),
  82. bottomNavigationBar: Container(
  83. color: SUB_COLOR,
  84. height: 68,
  85. padding: EdgeInsets.fromLTRB(15, 10, 15, 10),
  86. child: MaterialButton(
  87. elevation: 0,
  88. highlightElevation: 0,
  89. height: 48,
  90. minWidth: double.infinity,
  91. color: PRIMARY_COLOR,
  92. child: Text(
  93. '充值',
  94. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
  95. ),
  96. onPressed: () {
  97. Navigator.push(context, CupertinoPageRoute(builder: (context) => Recharge()));
  98. },
  99. ),
  100. ),
  101. body: RefreshIndicator(
  102. color: PRIMARY_COLOR,
  103. backgroundColor: Colors.white,
  104. onRefresh: () async {
  105. await Future.delayed(const Duration(seconds: 1));
  106. setState(() {
  107. walletList = [];
  108. isShow = false;
  109. currentPage = 1;
  110. });
  111. getWalletPage();
  112. },
  113. child: Container(
  114. child: Stack(
  115. children: <Widget>[
  116. CustomScrollView(
  117. controller: _controller,
  118. slivers: <Widget>[
  119. _sliverToBoxAdapter(context, userInfo),
  120. _sliverList(context),
  121. ],
  122. ),
  123. // _floatTab(context)
  124. ],
  125. ),
  126. ),
  127. ),
  128. );
  129. });
  130. }
  131. Widget _sliverToBoxAdapter(BuildContext context, UserInfo userInfo) {
  132. return SliverToBoxAdapter(
  133. child: Column(
  134. children: <Widget>[
  135. Container(
  136. height: 135,
  137. child: Column(
  138. mainAxisAlignment: MainAxisAlignment.center,
  139. children: <Widget>[
  140. Container(
  141. child: Text(userInfo.moneyCoin.toString(),
  142. style: TextStyle(
  143. color: PRIMARY_COLOR,
  144. fontSize: 51,
  145. fontWeight: FontWeight.bold,
  146. )),
  147. padding: EdgeInsets.only(top: 10),
  148. ),
  149. Row(
  150. mainAxisAlignment: MainAxisAlignment.center,
  151. children: <Widget>[
  152. Image(
  153. image: AssetImage('images/icon_jiner.png'),
  154. width: 20,
  155. ),
  156. Text('我的金币',
  157. style: TextStyle(
  158. color: PRIMARY_COLOR,
  159. fontSize: 14,
  160. ))
  161. ],
  162. )
  163. ],
  164. ),
  165. ),
  166. Container(
  167. width: double.infinity,
  168. height: 56,
  169. color: SUB_COLOR,
  170. child: Text(
  171. '余额明细',
  172. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
  173. ),
  174. padding: EdgeInsets.only(
  175. left: 15,
  176. top: 15,
  177. bottom: 15,
  178. ),
  179. )
  180. ],
  181. ));
  182. }
  183. Widget _sliverList(BuildContext context) {
  184. return SliverFixedExtentList(
  185. itemExtent: 66,
  186. delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
  187. if (index < walletList.length) {
  188. return Container(
  189. padding: EdgeInsets.all(15),
  190. decoration: BoxDecoration(
  191. border: BorderDirectional(top: BorderSide(width: 1, color: Color(0x2E000000), style: BorderStyle.solid)),
  192. color: SUB_COLOR,
  193. ),
  194. child: Row(
  195. mainAxisAlignment: MainAxisAlignment.center,
  196. children: <Widget>[
  197. Container(
  198. width: 53,
  199. child: Text(
  200. walletList[index]['money'].toString(),
  201. style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
  202. )),
  203. Expanded(
  204. flex: 1,
  205. child: Column(
  206. crossAxisAlignment: CrossAxisAlignment.start,
  207. children: <Widget>[
  208. Text(
  209. walletList[index]['remark'],
  210. maxLines: 1,
  211. overflow: TextOverflow.ellipsis,
  212. style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
  213. ),
  214. Text(
  215. readTimestamp(walletList[index]['createTime'], 'yyyy-MM-dd HH:mm:ss'),
  216. style: TextStyle(color: Color(0xFF727785), fontSize: 12, fontWeight: FontWeight.normal),
  217. )
  218. ],
  219. ),
  220. )
  221. ],
  222. ),
  223. );
  224. } else {
  225. return Center(
  226. child: Text(
  227. '没有更多了',
  228. style: TextStyle(color: Color(0xFF727785), fontSize: 12, fontWeight: FontWeight.normal),
  229. ),
  230. );
  231. }
  232. }, childCount: walletList.length + 1),
  233. );
  234. }
  235. }