YSSetPayPass.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:ysairplane2/base/YSBase.dart';
  5. import 'package:ysairplane2/code/YSInputPayPass.dart';
  6. import 'package:ysairplane2/tools/YSNetWorking.dart';
  7. import 'package:ysairplane2/tools/YSTools.dart';
  8. class YSSetPayPass extends StatefulWidget {
  9. @override
  10. _YSSetPayPassState createState() => _YSSetPayPassState();
  11. }
  12. class _YSSetPayPassState extends State<YSSetPayPass> {
  13. TextEditingController _phoneStr = TextEditingController();
  14. TextEditingController _codeStr = TextEditingController();
  15. int _number = 60;
  16. Timer _timer;
  17. @override
  18. void dispose() {
  19. if(_timer!=null){
  20. _timer.cancel();
  21. }
  22. super.dispose();
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return YSBase(
  27. ystitle: '设置支付密码',
  28. yschild: Column(
  29. children: [
  30. Container(
  31. height: hsp(90),
  32. padding: EdgeInsets.only(left: wsp(20),right: wsp(20)),
  33. margin: EdgeInsets.only(top: hsp(138),left: wsp(50),right: wsp(50)),
  34. color: Color(0xFFF5F5F7),
  35. child: CupertinoTextField(
  36. placeholder: '请输入手机号',
  37. style: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)),
  38. placeholderStyle: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)),
  39. decoration: BoxDecoration(),
  40. suffix: GestureDetector(child: Text(_number==60?'获取验证码':'$_number秒',style: TextStyle(fontSize: zsp(30),color: Color(0xFF0079FF)),),
  41. onTap: (){if(_number==60)_getCodeData();},),
  42. prefix: Container(
  43. padding: EdgeInsets.only(right: wsp(20)),
  44. margin: EdgeInsets.only(right: wsp(20)),
  45. height: hsp(40),
  46. alignment: Alignment.center,
  47. child: Text('+86',style: TextStyle(fontSize: zsp(32),color: Color(0xFF1E1721)),),
  48. decoration: BoxDecoration(
  49. border: Border(right: BorderSide(color: Color(0xFFCDCDD2)))
  50. ),
  51. ),
  52. keyboardType: TextInputType.phone,
  53. controller: _phoneStr,
  54. ),
  55. ),
  56. Container(
  57. height: hsp(90),
  58. padding: EdgeInsets.only(left: wsp(20),right: wsp(20)),
  59. margin: EdgeInsets.only(top: hsp(50),left: wsp(50),right: wsp(50)),
  60. color: Color(0xFFF5F5F7),
  61. child: CupertinoTextField(
  62. placeholder: '请输入短信验证码',
  63. style: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)),
  64. placeholderStyle: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)),
  65. decoration: BoxDecoration(),
  66. suffix: Icon(Icons.close,color: Color(0xFF75788C),size: hsp(40),),
  67. suffixMode: OverlayVisibilityMode.editing,
  68. controller: _codeStr,
  69. keyboardType: TextInputType.numberWithOptions(),
  70. ),
  71. ),
  72. GestureDetector(
  73. onTap: (){
  74. if(_codeStr.text.isEmpty){
  75. ysFlutterToast(context, '验证码不能为空');
  76. return;
  77. }
  78. FocusScope.of(context).unfocus();
  79. _timer.cancel();
  80. Navigator.of(context).push(
  81. CupertinoPageRoute(
  82. builder: (context){
  83. return YSInputPayPass(code: _codeStr.text,);
  84. }
  85. )
  86. );
  87. },
  88. child: Container(
  89. height: hsp(90),
  90. width: MediaQuery.of(context).size.width-wsp(50)*2,
  91. alignment: Alignment.center,
  92. margin: EdgeInsets.only(top: hsp(120)),
  93. decoration: BoxDecoration(
  94. color: Color(0xFF3B7EF2),
  95. borderRadius: BorderRadius.all(Radius.circular(5))
  96. ),
  97. child: Text('下一步',style: TextStyle(fontSize: zsp(34),color: Colors.white),),
  98. ),
  99. ),
  100. ],
  101. ),
  102. );
  103. }
  104. _getCodeData() async{
  105. FocusScope.of(context).unfocus();
  106. if(_phoneStr.text.isEmpty){
  107. ysFlutterToast(context, '手机号码不能为空');
  108. return;
  109. }
  110. if(isChinaPhoneLegal(_phoneStr.text)==false){
  111. ysFlutterToast(context, '手机号码格式不正确');
  112. return;
  113. }
  114. _timer = Timer.periodic(Duration(seconds: 1), (timer){
  115. setState(() {
  116. if(_number<=1){
  117. _number = 60;
  118. _timer.cancel();
  119. }else{
  120. _number--;
  121. }
  122. });
  123. });
  124. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/getVerificationCode',parameter: {'phone':_phoneStr.text});
  125. if(dict!=null){
  126. }
  127. }
  128. }