recharge.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import 'package:flutter/material.dart';
  2. import 'package:twong/api/index.dart';
  3. import 'package:twong/utils/index.dart';
  4. import 'package:twong/models/index.dart';
  5. import 'package:twong/config/style.dart';
  6. import 'package:twong/router/index.dart';
  7. import 'package:twong/widgets/app_bar.dart';
  8. import 'package:twong/widgets/payment.dart';
  9. class RechargePage extends StatefulWidget {
  10. @override
  11. State<StatefulWidget> createState() {
  12. return _RechargeState();
  13. }
  14. }
  15. class _RechargeState extends State<RechargePage> {
  16. RechargeIndex _data;
  17. RechargeData _selected;
  18. TextEditingController _inputCtrl = TextEditingController();
  19. @override
  20. void initState() {
  21. super.initState();
  22. loadData();
  23. }
  24. loadData() {
  25. Network.inst.getRecharge().then((value){
  26. setState(() {
  27. _data = value;
  28. _selected = _data.recharge_quota.first;
  29. });
  30. });
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. backgroundColor: DColors.back,
  36. appBar: DAppBar("充值中心", actions: [
  37. InkWell(
  38. onTap: () {
  39. Navigator.pushNamed(context, RouteNames.billRecord, arguments: 2);
  40. },
  41. highlightColor: Colors.transparent,
  42. child: Container(
  43. margin: EdgeInsets.only(right: 12.px),
  44. alignment: Alignment.center,
  45. child: Text("充值记录"),
  46. ),
  47. )
  48. ]),
  49. body: SafeArea(
  50. child: ListView(
  51. physics: ClampingScrollPhysics(),
  52. children: [
  53. Container(
  54. height: 500.px,
  55. child: Stack(
  56. children: [
  57. Container(
  58. height: 128.px,
  59. width: MediaQuery.of(context).size.width,
  60. color: DColors.Main,
  61. child: Column(
  62. mainAxisAlignment: MainAxisAlignment.center,
  63. children: [
  64. Text("我的余额", style: TextStyle(color: Colors.white,
  65. fontSize: 12.px)),
  66. RichText(text: TextSpan(
  67. text: I18n.$,
  68. style: TextStyle(fontSize: 12.px),
  69. children: [
  70. TextSpan(
  71. text: _data == null ? ""
  72. : Utils.formatRMB(_data.balance),
  73. style: TextStyle(fontSize: 26.px),
  74. )
  75. ]
  76. ))
  77. ],
  78. ),
  79. ),
  80. Positioned(child: Container(
  81. padding: EdgeInsets.all(6.px),
  82. width: MediaQuery.of(context).size.width,
  83. decoration: BoxDecoration(
  84. color: Colors.white,
  85. borderRadius: BorderRadius.circular(12.px)
  86. ),
  87. child: _data == null ? Utils.loadingWidget : _buildList(),
  88. ), top: 120.px, left: 0)
  89. ],
  90. ),
  91. )
  92. ],
  93. ),
  94. ),
  95. );
  96. }
  97. Widget _buildList() {
  98. List<Widget> widgets = List<Widget>();
  99. for (var item in _data.recharge_quota) {
  100. widgets.add(InkWell(
  101. onTap: () {
  102. setState(() {
  103. _selected = item;
  104. });
  105. FocusScope.of(context).requestFocus(FocusNode());
  106. },
  107. child: Container(
  108. height: 48.px,
  109. width: 100.px,
  110. decoration: BoxDecoration(
  111. color: _selected.id == item.id ? DColors.Main : Colors.black12,
  112. borderRadius: BorderRadius.circular(12.px)
  113. ),
  114. padding: EdgeInsets.all(6.px),
  115. margin: EdgeInsets.only(bottom: 8.px, left: 6.px, right: 6.px),
  116. child: Column(
  117. children: [
  118. Text(Utils.formatRMB(item.price, cn: true), style: TextStyle(
  119. color: _selected.id == item.id ? Colors.white : Colors.black
  120. )),
  121. Text("赠送:${Utils.formatRMB(item.price, cn: true)}", style:
  122. TextStyle(color: _selected.id == item.id ? Colors.white
  123. : Colors.black
  124. ))
  125. ],
  126. ),
  127. ),
  128. ));
  129. }
  130. widgets.add(Container(
  131. height: 48.px,
  132. width: 100.px,
  133. decoration: BoxDecoration(
  134. color: _selected.id == 0 ? DColors.Main : Colors.black12,
  135. borderRadius: BorderRadius.circular(12.px)
  136. ),
  137. padding: EdgeInsets.all(6.px),
  138. margin: EdgeInsets.only(bottom: 8.px, left: 6.px, right: 6.px),
  139. child: TextField(
  140. onTap: () {
  141. var data = RechargeData();
  142. data.id = 0;
  143. setState(() {
  144. _selected = data;
  145. });
  146. },
  147. onChanged: (value) {
  148. _selected.price = value.toString();
  149. },
  150. style: TextStyle(color: _selected.id == 0 ? Colors.white
  151. : Colors.black),
  152. controller: _inputCtrl,
  153. textAlign: TextAlign.center,
  154. keyboardType: TextInputType.number,
  155. decoration: InputDecoration(
  156. hintText: "其他",
  157. hintStyle: TextStyle(color: _selected.id == 0 ? Colors.white
  158. : Colors.black),
  159. border: InputBorder.none
  160. ),
  161. ),
  162. ));
  163. return Container(
  164. margin: EdgeInsets.only(left: 12.px, right: 12.px),
  165. child: Column(
  166. children: [
  167. Wrap(alignment: WrapAlignment.center, children: widgets),
  168. _buildInfo(),
  169. _buildButton()
  170. ]),
  171. );
  172. }
  173. Widget _buildInfo() {
  174. List<Widget> widgets = List<Widget>();
  175. widgets.add(Text("注意事项", style: TextStyle(fontWeight: FontWeight.bold)));
  176. for(var item in _data.recharge_attention) {
  177. widgets.add(Text(item.toString()));
  178. }
  179. return Container(
  180. width: double.infinity,
  181. margin: EdgeInsets.only(top: 12.px),
  182. child: Column(
  183. crossAxisAlignment: CrossAxisAlignment.start,
  184. children: widgets,
  185. ),
  186. );
  187. }
  188. Widget _buildButton() {
  189. return Container(
  190. width: double.infinity,
  191. margin: EdgeInsets.only(top: 12.px, bottom: 6.px),
  192. child: FlatButton(
  193. onPressed: _goPay,
  194. color: DColors.Main,
  195. shape: StadiumBorder(),
  196. child: Text("立即充值", style: TextStyle(color: Colors.white)),
  197. ),
  198. );
  199. }
  200. _goPay() {
  201. showModalBottomSheet(
  202. context: context,
  203. shape: RoundedRectangleBorder(borderRadius: BorderRadius.only(
  204. topLeft: Radius.circular(10.px), topRight: Radius.circular(10.px)
  205. )),
  206. builder: (BuildContext context) {
  207. return Payment(PaymentInfo.recharge(_selected.id, _selected.price));
  208. });
  209. }
  210. }