MyWallet.dart 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import '../styles/colors.dart';
  5. import 'package:redux/redux.dart';
  6. import 'package:flutter_redux/flutter_redux.dart';
  7. import '../redux/AppState.dart';
  8. import '../model/UserInfo.dart';
  9. import '../net/HttpManager.dart';
  10. import '../net/Result.dart';
  11. import 'dart:ui';
  12. import '../styles/totast.dart';
  13. import 'Recharge.dart';
  14. class MyWallet extends StatefulWidget {
  15. @override
  16. MyWalletState createState() => MyWalletState();
  17. }
  18. class MyWalletState extends State<MyWallet> {
  19. ScrollController _controller;
  20. List walletList;
  21. bool isShow = false;
  22. num _topHeight;
  23. int currentPage = 1;
  24. bool canNext = true;
  25. Future<void> getWalletPage() async {
  26. Toast.show(context, '加载中', -1, 'loading');
  27. canNext = false;
  28. Result res = await HttpManager.get('memberCoin/page',
  29. data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'currentPage': currentPage, 'pageNumber': 20});
  30. Toast.hide();
  31. if (res.success) {
  32. if (currentPage == 1) {
  33. walletList = [];
  34. }
  35. setState(() {
  36. walletList.addAll(res.data['pp']);
  37. });
  38. if (res.data['page']['totalNumber'] > currentPage) {
  39. canNext = true;
  40. }
  41. } else {}
  42. }
  43. @override
  44. void initState() {
  45. super.initState();
  46. walletList = List<Map>();
  47. Future.delayed(Duration.zero, () {
  48. getWalletPage();
  49. });
  50. _controller = ScrollController();
  51. isShow = false;
  52. _controller.addListener(() {
  53. if (_controller.position.pixels == _controller.position.maxScrollExtent && canNext) {
  54. currentPage++;
  55. getWalletPage();
  56. }
  57. if (_controller.position.pixels >= _topHeight + 82) {
  58. setState(() {
  59. isShow = true;
  60. });
  61. } else {
  62. setState(() {
  63. isShow = false;
  64. });
  65. }
  66. });
  67. }
  68. @override
  69. void dispose() {
  70. super.dispose();
  71. _controller.dispose();
  72. }
  73. @override
  74. Widget build(BuildContext context) {
  75. ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
  76. return StoreConnector<AppState, UserInfo>(
  77. converter: (Store store) => store.state.userInfo,
  78. builder: (context, userInfo) {
  79. return Scaffold(
  80. body: RefreshIndicator(
  81. color: PRIMARY_COLOR,
  82. backgroundColor: Colors.white,
  83. onRefresh: () async {
  84. await Future.delayed(const Duration(seconds: 1));
  85. setState(() {
  86. walletList = [];
  87. isShow = false;
  88. currentPage = 1;
  89. });
  90. getWalletPage();
  91. },
  92. child: Container(
  93. color: BG_COLOR,
  94. child: Stack(
  95. children: <Widget>[
  96. CustomScrollView(
  97. controller: _controller,
  98. slivers: <Widget>[
  99. SliverAppBar(
  100. backgroundColor: PRIMARY_COLOR,
  101. title: Text(isShow ? '余额明细' : ''),
  102. centerTitle: true,
  103. pinned: true,
  104. ),
  105. _sliverToBoxAdapter(context, userInfo),
  106. _sliverList(context),
  107. ],
  108. ),
  109. // _floatTab(context)
  110. ],
  111. ),
  112. ),
  113. ));
  114. });
  115. }
  116. //浮块
  117. Widget _floatTab(BuildContext context) {
  118. _topHeight = 56 + MediaQueryData.fromWindow(window).padding.top;
  119. return Positioned(
  120. top: isShow ? _topHeight : -46,
  121. child: Container(
  122. width: window.physicalSize.width / window.devicePixelRatio,
  123. height: 46,
  124. color: PRIMARY_COLOR,
  125. child: _newRouterTab(context),
  126. ),
  127. );
  128. }
  129. Widget _sliverToBoxAdapter(BuildContext context, UserInfo userInfo) {
  130. return SliverToBoxAdapter(
  131. child: Column(
  132. children: <Widget>[
  133. Container(
  134. alignment: Alignment.center,
  135. width: double.infinity,
  136. height: 194,
  137. decoration: BoxDecoration(
  138. //背景装饰
  139. gradient: LinearGradient(
  140. begin: Alignment.bottomRight,
  141. colors: [Color(0xFFFFA6A2), PRIMARY_COLOR],
  142. )),
  143. child: Stack(
  144. overflow: Overflow.visible,
  145. children: <Widget>[
  146. Container(
  147. width: 216,
  148. height: 192,
  149. decoration: BoxDecoration(
  150. image: DecorationImage(
  151. image: AssetImage('images/img_wodeshouyi.png'),
  152. fit: BoxFit.contain,
  153. )),
  154. child: Column(
  155. mainAxisAlignment: MainAxisAlignment.center,
  156. children: <Widget>[
  157. Container(
  158. child: Text(userInfo.moneyCoin.toString(),
  159. style: TextStyle(
  160. color: PRIMARY_COLOR,
  161. fontSize: 51,
  162. fontWeight: FontWeight.w900,
  163. )),
  164. padding: EdgeInsets.only(top: 10),
  165. ),
  166. Row(
  167. mainAxisAlignment: MainAxisAlignment.center,
  168. children: <Widget>[
  169. Image(
  170. image: AssetImage('images/icon_jinbi_xiao_hong.png'),
  171. width: 20,
  172. ),
  173. Text('我的金币',
  174. style: TextStyle(
  175. color: PRIMARY_COLOR,
  176. fontSize: 14,
  177. ))
  178. ],
  179. )
  180. ],
  181. ),
  182. ),
  183. // Positioned(
  184. // bottom: -23,
  185. // left: -(ScreenUtil().setWidth(345) - 216) / 2,
  186. // child: Container(
  187. // width: ScreenUtil().setWidth(345),
  188. // height: 46,
  189. // color: PRIMARY_COLOR,
  190. // child: _newRouterTab(context),
  191. // ),
  192. // )
  193. ],
  194. ),
  195. ),
  196. Container(
  197. width: double.infinity,
  198. child: Text(
  199. '余额明细',
  200. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500),
  201. ),
  202. padding: EdgeInsets.only(
  203. left: 15,
  204. top: 15,
  205. bottom: 15,
  206. ),
  207. )
  208. ],
  209. ));
  210. }
  211. //充值,提现
  212. Widget _newRouterTab(BuildContext context) {
  213. return Row(
  214. children: <Widget>[
  215. Expanded(
  216. flex: 1,
  217. child: GestureDetector(
  218. child: Container(
  219. padding: EdgeInsets.all(10),
  220. child: Text(
  221. '提现',
  222. textAlign: TextAlign.center,
  223. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500),
  224. ),
  225. ),
  226. onTap: () {},
  227. ),
  228. ),
  229. Container(
  230. width: 1,
  231. height: 20,
  232. color: Color(0x2E000000),
  233. ),
  234. Expanded(
  235. flex: 1,
  236. child: GestureDetector(
  237. child: Container(
  238. padding: EdgeInsets.all(10),
  239. child: Text(
  240. '充值',
  241. textAlign: TextAlign.center,
  242. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500),
  243. )),
  244. onTap: () {
  245. Navigator.push(context, CupertinoPageRoute(builder: (context) => Rechrage()));
  246. },
  247. ),
  248. )
  249. ],
  250. );
  251. }
  252. Widget _sliverList(BuildContext context) {
  253. return SliverFixedExtentList(
  254. itemExtent: 66,
  255. delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
  256. if (index < walletList.length) {
  257. return Container(
  258. padding: EdgeInsets.all(15),
  259. decoration: BoxDecoration(
  260. border: BorderDirectional(top: BorderSide(width: 1, color: Color(0x2E000000), style: BorderStyle.solid)),
  261. color: BG_COLOR,
  262. ),
  263. child: Row(
  264. mainAxisAlignment: MainAxisAlignment.center,
  265. children: <Widget>[
  266. Container(
  267. width: 53,
  268. child: Text(
  269. walletList[index]['money'].toString(),
  270. style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w500),
  271. )),
  272. Expanded(
  273. flex: 1,
  274. child: Column(
  275. crossAxisAlignment: CrossAxisAlignment.start,
  276. children: <Widget>[
  277. Text(
  278. walletList[index]['remark'],
  279. maxLines: 1,
  280. overflow: TextOverflow.ellipsis,
  281. style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
  282. ),
  283. Text(
  284. readTimestamp(walletList[index]['createTime'], 'yyyy-MM-dd HH:mm:ss'),
  285. style: TextStyle(color: Color(0xFF727785), fontSize: 12, fontWeight: FontWeight.w400),
  286. )
  287. ],
  288. ),
  289. )
  290. ],
  291. ),
  292. );
  293. } else {
  294. return Center(
  295. child: Text(
  296. '没有更多了',
  297. style: TextStyle(color: Color(0xFF727785), fontSize: 12, fontWeight: FontWeight.w400),
  298. ),
  299. );
  300. }
  301. }, childCount: walletList.length + 1),
  302. );
  303. }
  304. }