MyWallet.dart 10 KB

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