wallet.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import 'package:bot_toast/bot_toast.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:twong/api/index.dart';
  5. import 'package:twong/utils/index.dart';
  6. import 'package:twong/config/style.dart';
  7. import 'package:twong/models/balance.dart';
  8. import 'package:twong/utils/sentry.dart';
  9. import 'package:twong/widgets/future_widget.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. _balance = Cache.get(SaveKey.balance);
  27. }
  28. loadData () async {
  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. SentryUtils.reportError("error", "stackTrace");
  39. }
  40. Widget _buildWallet () {
  41. return Container(
  42. height: 168.px,
  43. margin: EdgeInsets.only(right: 16.px, left: 16.px),
  44. decoration: BoxDecoration(
  45. color: Colors.red,
  46. borderRadius: BorderRadius.circular(8.px),
  47. ),
  48. child: Container(
  49. padding: EdgeInsets.all(12.px),
  50. child: Column(
  51. children: <Widget>[
  52. Row(
  53. children: <Widget>[
  54. Expanded(child: Column(
  55. crossAxisAlignment: CrossAxisAlignment.start,
  56. children: <Widget>[
  57. Text('总资产(元)', style: TextStyle(color: Colors.white, fontSize: 12.px, fontWeight: FontWeight.w100)),
  58. RichText(text: TextSpan(
  59. text: "¥",
  60. style: TextStyle(color: Colors.white, fontSize: 18),
  61. children: [ TextSpan(
  62. style: TextStyle(color: Colors.white, fontSize: 30),
  63. text: _balance?.now_money == null ? '--' : _balance.now_money
  64. )]
  65. )),
  66. ],
  67. )),
  68. FlatButton(
  69. onPressed: () {},
  70. color: Colors.white,
  71. shape: RoundedRectangleBorder(side: BorderSide.none, borderRadius: BorderRadius.all(Radius.circular(16.px))),
  72. child: Text('充值', style: TextStyle(color: Colors.red)),
  73. )
  74. ],
  75. ),
  76. Container(
  77. padding: EdgeInsets.only(top: 40.px),
  78. child: Row(
  79. children: <Widget>[
  80. Expanded(child: Column(
  81. crossAxisAlignment: CrossAxisAlignment.start,
  82. children: <Widget>[
  83. Text('累计充值(元)', style: TextStyle(color: Colors.white, fontSize: 12.px, fontWeight: FontWeight.w100)),
  84. RichText(text: TextSpan(
  85. text: "¥",
  86. style: TextStyle(color: Colors.white, fontSize: 12),
  87. children: [ TextSpan(
  88. style: TextStyle(color: Colors.white, fontSize: 20),
  89. text: _balance?.recharge == null ? '--' : _balance.recharge.toString(),
  90. )]
  91. )),
  92. ],
  93. )),
  94. Expanded(child: Column(
  95. crossAxisAlignment: CrossAxisAlignment.start,
  96. children: <Widget>[
  97. Text('累计消费(元)', style: TextStyle(color: Colors.white, fontSize: 12.px, fontWeight: FontWeight.w100)),
  98. RichText(text: TextSpan(
  99. text: "¥",
  100. style: TextStyle(color: Colors.white, fontSize: 12),
  101. children: [ TextSpan(
  102. style: TextStyle(color: Colors.white, fontSize: 20),
  103. text: _balance?.orderStatusSum == null ? '--' : _balance.orderStatusSum.toString(),
  104. )]
  105. )),
  106. ],
  107. )),
  108. ],
  109. ),
  110. )
  111. ],
  112. ),
  113. )
  114. );
  115. }
  116. Widget _buildMenu () {
  117. return Container(
  118. padding: EdgeInsets.only(top: 16.px),
  119. child: Flex(
  120. direction: Axis.horizontal,
  121. children: <Widget>[
  122. Expanded(child: Container(
  123. child: GestureDetector(
  124. onTap: () {},
  125. child: Column(
  126. children: <Widget>[
  127. Container(height: 6,),
  128. Icon(Icons.library_books, color: Colors.red),
  129. Text('账单记录', style: TextStyle(fontWeight: FontWeight.w200, fontSize: 12.px)),
  130. ],
  131. ),
  132. ),
  133. ),),
  134. Expanded(child: Container(
  135. child: GestureDetector(
  136. onTap: () {},
  137. child: Column(
  138. children: <Widget>[
  139. Container(height: 6.px),
  140. Icon(Icons.attach_money, color: Colors.red),
  141. Text('消费记录', style: TextStyle(fontWeight: FontWeight.w200, fontSize: 12.px)),
  142. ],
  143. ),
  144. ),
  145. ),),
  146. Expanded(child: Container(
  147. child: GestureDetector(
  148. onTap: () {},
  149. child: Column(
  150. children: <Widget>[
  151. Container(height: 6.px),
  152. Icon(Icons.monetization_on, color: Colors.red),
  153. Text('充值记录', style: TextStyle(fontWeight: FontWeight.w200, fontSize: 12.px)),
  154. ],
  155. ),
  156. ),
  157. ),),
  158. Expanded(child: Container(
  159. child: GestureDetector(
  160. onTap: () {},
  161. child: Column(
  162. children: <Widget>[
  163. Container(height: 6.px),
  164. Icon(Icons.receipt, color: Colors.red),
  165. Text('积分记录', style: TextStyle(fontWeight: FontWeight.w200, fontSize: 12.px)),
  166. ],
  167. ),
  168. ),
  169. ),)
  170. ],
  171. ),
  172. );
  173. }
  174. @override
  175. Widget build(BuildContext context) {
  176. return Scaffold (
  177. backgroundColor: DColors.back,
  178. body: SafeArea(
  179. child: ListView(
  180. physics: ClampingScrollPhysics(),
  181. children: <Widget>[
  182. _buildWallet(),
  183. _buildMenu(),
  184. Container(
  185. height: 1.px,
  186. margin: EdgeInsets.all(10.px),
  187. color: Color.fromARGB(255, 223, 223, 223),
  188. )
  189. ],
  190. ),
  191. )
  192. );
  193. }
  194. }