YSSetPayPass.dart 4.6 KB

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