wallet.dart 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:twong/api/index.dart';
  4. import 'package:twong/pages/tabs.dart';
  5. import 'package:twong/router/base.dart';
  6. import 'package:twong/utils/index.dart';
  7. import 'package:twong/utils/sentry.dart';
  8. import 'package:twong/config/style.dart';
  9. import 'package:twong/models/balance.dart';
  10. class WalletPage extends StatefulWidget {
  11. @override
  12. State<StatefulWidget> createState() {
  13. return _WalletPageState();
  14. }
  15. }
  16. class _WalletPageState extends State<WalletPage> {
  17. Balance _balance;
  18. @override
  19. void initState() {
  20. super.initState();
  21. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  22. statusBarBrightness: Brightness.light,
  23. statusBarIconBrightness: Brightness.light,
  24. ));
  25. loadData();
  26. }
  27. loadData () async {
  28. _balance = Cache.get(SaveKey.balance);
  29. Network.inst.getBalance().then((balance) {
  30. if(!mounted) return;
  31. setState(() {
  32. _balance = balance;
  33. });
  34. Cache.set(SaveKey.balance, _balance);
  35. }).catchError((err) {
  36. Log.e(err);
  37. });
  38. }
  39. Widget _buildWallet () {
  40. return Container(
  41. height: 168.px,
  42. margin: EdgeInsets.only(right: 12.px, left: 12.px),
  43. decoration: BoxDecoration(
  44. color: Colors.red,
  45. borderRadius: BorderRadius.circular(8.px),
  46. ),
  47. child: Container(
  48. padding: EdgeInsets.all(12.px),
  49. child: Column(
  50. children: <Widget>[
  51. Row(
  52. children: <Widget>[
  53. Expanded(child: Column(
  54. crossAxisAlignment: CrossAxisAlignment.start,
  55. children: <Widget>[
  56. Text('总资产(元)', style: TextStyle(color: Colors.white,
  57. fontSize: 12.px,
  58. fontWeight: FontWeight.w100)),
  59. RichText(text: TextSpan(
  60. text: "¥",
  61. style: TextStyle(color: Colors.white,
  62. fontSize: 18),
  63. children: [ TextSpan(
  64. style: TextStyle(
  65. color: Colors.white, fontSize: 30),
  66. text: _balance?.now_money == null
  67. ? '--'
  68. : _balance.now_money),
  69. ])
  70. ),
  71. ])
  72. ),
  73. FlatButton(
  74. onPressed: () {
  75. Navigator.pushNamed(context, RouteNames.recharge);
  76. },
  77. color: Colors.white,
  78. highlightColor: Colors.transparent,
  79. shape: RoundedRectangleBorder(side: BorderSide.none,
  80. borderRadius: BorderRadius.all(
  81. Radius.circular(16.px))),
  82. child: Text('充值', style: TextStyle(color: Colors.red)),
  83. )
  84. ]),
  85. Container(
  86. padding: EdgeInsets.only(top: 40.px),
  87. child: Row(
  88. children: <Widget>[
  89. Expanded(child: Column(
  90. crossAxisAlignment: CrossAxisAlignment.start,
  91. children: <Widget>[
  92. Text('累计充值(元)', style: TextStyle(color: Colors
  93. .white,
  94. fontSize: 12.px,
  95. fontWeight: FontWeight.w100)),
  96. RichText(text: TextSpan(
  97. text: "¥",
  98. style: TextStyle(
  99. color: Colors.white, fontSize: 12),
  100. children: [ TextSpan(
  101. style: TextStyle(
  102. color: Colors.white, fontSize: 20),
  103. text: _balance?.recharge == null
  104. ? '--'
  105. : _balance.recharge.toString(),
  106. ),
  107. ])
  108. ),
  109. ])
  110. ),
  111. Expanded(child: Column(
  112. crossAxisAlignment: CrossAxisAlignment.start,
  113. children: <Widget>[
  114. Text('累计消费(元)', style: TextStyle(color: Colors
  115. .white,
  116. fontSize: 12.px,
  117. fontWeight: FontWeight.w100)),
  118. RichText(text: TextSpan(
  119. text: "¥",
  120. style: TextStyle(
  121. color: Colors.white, fontSize: 12),
  122. children: [ TextSpan(
  123. style: TextStyle(
  124. color: Colors.white, fontSize: 20),
  125. text: _balance?.orderStatusSum == null
  126. ? '--'
  127. : _balance.orderStatusSum.toString(),),
  128. ])),
  129. ])),
  130. ]),
  131. ),
  132. ]),
  133. )
  134. );
  135. }
  136. Widget _buildMenu () {
  137. return Container(
  138. padding: EdgeInsets.all(6.px),
  139. margin: EdgeInsets.only(top: 12.px, left: 12.px, right: 12.px),
  140. decoration: BoxDecoration(
  141. color: Colors.white,
  142. borderRadius: BorderRadius.circular(6.px)
  143. ),
  144. child: Flex(
  145. direction: Axis.horizontal,
  146. children: <Widget>[
  147. Expanded(child: Container(
  148. child: GestureDetector(
  149. onTap: () {
  150. Navigator.pushNamed(context,
  151. RouteNames.billRecord, arguments: 0);
  152. },
  153. child: Column(
  154. children: <Widget>[
  155. Icon(Icons.library_books, color: Colors.red),
  156. Container(height: 6),
  157. Text('账单记录', style: TextStyle(
  158. fontWeight: FontWeight.w200, fontSize: 12.px)),
  159. ],
  160. ),
  161. ),
  162. ),),
  163. Expanded(child: Container(
  164. child: GestureDetector(
  165. onTap: () {
  166. Navigator.pushNamed(context,
  167. RouteNames.billRecord, arguments: 1);
  168. },
  169. child: Column(
  170. children: <Widget>[
  171. Icon(Icons.attach_money, color: Colors.red),
  172. Container(height: 6.px),
  173. Text('消费记录', style: TextStyle(
  174. fontWeight: FontWeight.w200, fontSize: 12.px)),
  175. ],
  176. ),
  177. ),
  178. ),),
  179. Expanded(child: Container(
  180. child: GestureDetector(
  181. onTap: () {
  182. Navigator.pushNamed(context,
  183. RouteNames.billRecord, arguments: 2);
  184. },
  185. child: Column(
  186. children: <Widget>[
  187. Icon(Icons.monetization_on, color: Colors.red),
  188. Container(height: 6.px),
  189. Text('充值记录', style: TextStyle(
  190. fontWeight: FontWeight.w200, fontSize: 12.px)),
  191. ],
  192. ),
  193. ),
  194. ),),
  195. Expanded(child: Container(
  196. child: GestureDetector(
  197. onTap: () {
  198. Navigator.pushNamed(context, RouteNames.integralRecord);
  199. },
  200. child: Column(
  201. children: <Widget>[
  202. Icon(Icons.receipt, color: Colors.red),
  203. Container(height: 6.px),
  204. Text('积分记录', style: TextStyle(
  205. fontWeight: FontWeight.w200, fontSize: 12.px)),
  206. ]),
  207. ),
  208. ))
  209. ]),
  210. );
  211. }
  212. @override
  213. Widget build(BuildContext context) {
  214. return Scaffold(
  215. backgroundColor: DColors.back,
  216. body: SafeArea(
  217. child: ListView(
  218. physics: ClampingScrollPhysics(),
  219. children: <Widget>[
  220. _buildWallet(),
  221. _buildMenu(),
  222. Divider()
  223. ]),
  224. )
  225. );
  226. }
  227. }