Recharge.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'dart:ui';
  5. class Rechrage extends StatefulWidget {
  6. @override
  7. RechrageState createState() => RechrageState();
  8. }
  9. class RechrageState extends State<Rechrage> {
  10. List<Map> moenyList = [
  11. {
  12. 'title': '10金币',
  13. 'money': 10,
  14. },
  15. {
  16. 'title': '50金币',
  17. 'money': 50,
  18. },
  19. {
  20. 'title': '100金币',
  21. 'money': 100,
  22. },
  23. {
  24. 'title': '300金币',
  25. 'money': 300,
  26. },
  27. {
  28. 'title': '500金币',
  29. 'money': 500,
  30. }
  31. ];
  32. bool isInput = false;
  33. int choosemoeny = 0;
  34. bool autoChoose = false;
  35. FocusNode _focusNode = FocusNode();
  36. @override
  37. void initState() {
  38. super.initState();
  39. _focusNode.addListener(_focusNodeListener);
  40. }
  41. Future<Null> _focusNodeListener() async {
  42. if (_focusNode.hasFocus) {
  43. setState(() {
  44. if (!autoChoose) {
  45. autoChoose = true;
  46. choosemoeny = 0;
  47. }
  48. isInput = true;
  49. });
  50. } else {
  51. setState(() {
  52. isInput = false;
  53. });
  54. }
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
  59. return Scaffold(
  60. appBar: AppBar(
  61. // backgroundColor: PRIMARY_COLOR,
  62. title: Text('充值'),
  63. centerTitle: true,
  64. elevation: 0,
  65. ),
  66. body: GestureDetector(
  67. ///透明也响应处理
  68. behavior: HitTestBehavior.translucent,
  69. onTap: () {
  70. ///触摸手气键盘
  71. FocusScope.of(context).requestFocus(FocusNode());
  72. },
  73. child: RefreshIndicator(
  74. color: PRIMARY_COLOR,
  75. backgroundColor: Colors.white,
  76. onRefresh: () async {
  77. await Future.delayed(const Duration(seconds: 1));
  78. },
  79. child: Container(
  80. color: BG_COLOR,
  81. child: Column(
  82. children: <Widget>[_useGride(context)],
  83. ),
  84. ),
  85. )));
  86. }
  87. Widget _useGride(BuildContext context) {
  88. return Container(
  89. padding: EdgeInsets.all(ScreenUtil().setWidth(15)),
  90. width: double.infinity,
  91. child: Wrap(
  92. alignment: WrapAlignment.spaceBetween,
  93. children: _allChooseBtn(context),
  94. ),
  95. );
  96. }
  97. List<Widget> _allChooseBtn(BuildContext context) {
  98. List<Widget> allWidget = List<Widget>.generate(moenyList.length, (int index) {
  99. return _chooseBtn(context, index);
  100. });
  101. Widget _input() {
  102. return Container(
  103. padding: EdgeInsets.only(left: 30, right: 5),
  104. color: autoChoose ? PRIMARY_COLOR : BG_SUB_COLOR,
  105. margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(5)),
  106. width: ScreenUtil().setWidth(170),
  107. height: ScreenUtil().setWidth(60),
  108. child: TextField(
  109. focusNode: _focusNode,
  110. textAlign: TextAlign.center,
  111. keyboardType: TextInputType.number,
  112. style: TextStyle(
  113. fontSize: 16,
  114. fontWeight: FontWeight.w500,
  115. color: Colors.white,
  116. ),
  117. decoration: InputDecoration(
  118. hintText: isInput ? '请输入金额' : '其他金额',
  119. hintStyle: TextStyle(color: Colors.white, fontSize: 14, fontWeight: isInput ? FontWeight.w500 : FontWeight.w400),
  120. suffixText: '金币',
  121. suffixStyle: TextStyle(fontSize: 13, fontWeight: FontWeight.w400, color: Colors.white),
  122. border: OutlineInputBorder(borderSide: BorderSide.none),
  123. ),
  124. onChanged: (String str) {
  125. //输入监听
  126. choosemoeny = int.parse(str);
  127. }));
  128. }
  129. allWidget.add(_input());
  130. return allWidget;
  131. }
  132. Widget _chooseBtn(BuildContext context, int index) {
  133. bool isChoose = false;
  134. if (!autoChoose && moenyList[index]['money'] == choosemoeny) {
  135. isChoose = true;
  136. }
  137. return Container(
  138. margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(5)),
  139. width: ScreenUtil().setWidth(170),
  140. height: ScreenUtil().setWidth(60),
  141. child: FlatButton(
  142. color: isChoose ? PRIMARY_COLOR : BG_SUB_COLOR,
  143. highlightColor: isChoose ? PRIMARY_COLOR.withOpacity(0.3) : BG_COLOR.withOpacity(0.3),
  144. child: Column(
  145. mainAxisAlignment: MainAxisAlignment.center,
  146. children: <Widget>[
  147. Text(moenyList[index]['title'], style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500, height: 1)),
  148. Text('¥' + moenyList[index]['money'].toString(),
  149. style: TextStyle(color: isChoose ? Colors.white : Color(0xFF727785), fontSize: 13, fontWeight: FontWeight.w400, height: 18 / 13)),
  150. ],
  151. ),
  152. onPressed: () {
  153. setState(() {
  154. autoChoose = false;
  155. choosemoeny = moenyList[index]['money'];
  156. FocusScope.of(context).requestFocus(FocusNode());
  157. });
  158. },
  159. ),
  160. );
  161. }
  162. }