import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:ysairplane/base/YSBase.dart'; import 'package:ysairplane/code/YSInputPayPass.dart'; import 'package:ysairplane/tools/YSNetWorking.dart'; import 'package:ysairplane/tools/YSTools.dart'; class YSSetPayPass extends StatefulWidget { @override _YSSetPayPassState createState() => _YSSetPayPassState(); } class _YSSetPayPassState extends State { TextEditingController _phoneStr = TextEditingController(); TextEditingController _codeStr = TextEditingController(); int _number = 60; Timer _timer; @override Widget build(BuildContext context) { return YSBase( ystitle: '设置支付密码', yschild: Column( children: [ Container( height: hsp(90), padding: EdgeInsets.only(left: wsp(20),right: wsp(20)), margin: EdgeInsets.only(top: hsp(138),left: wsp(50),right: wsp(50)), color: Color(0xFFF5F5F7), child: CupertinoTextField( placeholder: '请输入手机号', style: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)), placeholderStyle: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)), decoration: BoxDecoration(), suffix: GestureDetector(child: Text(_number==60?'获取验证码':'$_number秒',style: TextStyle(fontSize: zsp(30),color: Color(0xFF0079FF)),),onTap: (){if(_number==60)_getCodeData();},), prefix: Container( padding: EdgeInsets.only(right: wsp(20)), margin: EdgeInsets.only(right: wsp(20)), height: hsp(40), alignment: Alignment.center, child: Text('+86',style: TextStyle(fontSize: zsp(32),color: Color(0xFF1E1721)),), decoration: BoxDecoration( border: Border(right: BorderSide(color: Color(0xFFCDCDD2))) ), ), keyboardType: TextInputType.phone, controller: _phoneStr, ), ), Container( height: hsp(90), padding: EdgeInsets.only(left: wsp(20),right: wsp(20)), margin: EdgeInsets.only(top: hsp(50),left: wsp(50),right: wsp(50)), color: Color(0xFFF5F5F7), child: CupertinoTextField( placeholder: '请输入短信验证码', style: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)), placeholderStyle: TextStyle(fontSize: zsp(30),color: Color(0xFF75788C)), decoration: BoxDecoration(), suffix: Icon(Icons.close,color: Color(0xFF75788C),size: hsp(40),), suffixMode: OverlayVisibilityMode.editing, controller: _codeStr, keyboardType: TextInputType.numberWithOptions(), ), ), GestureDetector( onTap: (){ if(_codeStr.text.isEmpty){ ysFlutterToast(context, '验证码不能为空'); return; } FocusScope.of(context).unfocus(); _timer.cancel(); Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSInputPayPass(code: _codeStr.text,); } ) ); }, child: Container( height: hsp(90), width: MediaQuery.of(context).size.width-wsp(50)*2, alignment: Alignment.center, margin: EdgeInsets.only(top: hsp(120)), decoration: BoxDecoration( color: Color(0xFF3B7EF2), borderRadius: BorderRadius.all(Radius.circular(5)) ), child: Text('下一步',style: TextStyle(fontSize: zsp(34),color: Colors.white),), ), ), ], ), ); } _getCodeData() async{ FocusScope.of(context).unfocus(); if(_phoneStr.text.isEmpty){ ysFlutterToast(context, '手机号码不能为空'); return; } if(isChinaPhoneLegal(_phoneStr.text)==false){ ysFlutterToast(context, '手机号码格式不正确'); return; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/getVerificationCode',parameter: {'phone':_phoneStr.text}); if(dict!=null){ _timer = Timer.periodic(Duration(seconds: 1), (timer){ setState(() { if(_number<=1){ _number = 60; _timer.cancel(); }else{ _number--; } }); }); } } }