flutter中怎么實現(xiàn)發(fā)送驗證碼功能

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)flutter中怎么實現(xiàn)發(fā)送驗證碼功能,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

阜城網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,阜城網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為阜城上千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的阜城做網(wǎng)站的公司定做!

一個發(fā)送驗證碼的需求:包括限制文本框輸入長度和只允許輸入數(shù)字

class MyBody extends StatefulWidget { @override _MyBodyState createState() => _MyBodyState();} class _MyBodyState extends State<MyBody> { bool isButtonEnable=true;  //按鈕狀態(tài) 是否可點擊 String buttonText='發(fā)送驗證碼'; //初始文本 int count=60;      //初始倒計時時間 Timer timer;      //倒計時的計時器 TextEditingController mController=TextEditingController();  void _buttonClickListen(){ setState(() {  if(isButtonEnable){   //當(dāng)按鈕可點擊時  isButtonEnable=false; //按鈕狀態(tài)標(biāo)記  _initTimer();   return null;   //返回null按鈕禁止點擊  }else{     //當(dāng)按鈕不可點擊時//  debugPrint('false');  return null;    //返回null按鈕禁止點擊  } }); }   void _initTimer(){ timer = new Timer.periodic(Duration(seconds: 1), (Timer timer) {  count--;  setState(() {  if(count==0){   timer.cancel();    //倒計時結(jié)束取消定時器   isButtonEnable=true;  //按鈕可點擊   count=60;     //重置時間   buttonText='發(fā)送驗證碼';  //重置按鈕文本  }else{   buttonText='重新發(fā)送($count)'; //更新文本內(nèi)容  }  }); }); }   @override void dispose() { timer?.cancel();  //銷毀計時器 timer=null; super.dispose(); }   @override Widget build(BuildContext context) { return Container(  child: Column(//  mainAxisAlignment: MainAxisAlignment.center,  children: <Widget>[   Container(    color: Colors.white,    padding: EdgeInsets.only(left: 10,right: 10),    child: Row(     mainAxisAlignment: MainAxisAlignment.spaceBetween,//     crossAxisAlignment: CrossAxisAlignment.center,     crossAxisAlignment: CrossAxisAlignment.baseline,     textBaseline: TextBaseline.ideographic,     children: <Widget>[     Text('驗證碼',style: TextStyle(fontSize: 13,color: Color(0xff333333)),),     Expanded(      child: Padding(padding: EdgeInsets.only(left: 15,right: 15,top: 15),      child: TextFormField(      maxLines: 1,      onSaved: (value) { },      controller: mController,      textAlign: TextAlign.left,      inputFormatters: [WhitelistingTextInputFormatter.digitsOnly,LengthLimitingTextInputFormatter(6)],      decoration: InputDecoration(       hintText: ('填寫驗證碼'),       contentPadding: EdgeInsets.only(top: -5,bottom: 0),       hintStyle: TextStyle(       color: Color(0xff999999),       fontSize: 13,       ),       alignLabelWithHint: true,       border: OutlineInputBorder(borderSide: BorderSide.none),      ),      ),),     ),     Container(      width: 120,      child: FlatButton(      disabledColor: Colors.grey.withOpacity(0.1),  //按鈕禁用時的顏色      disabledTextColor: Colors.white,     //按鈕禁用時的文本顏色      textColor:isButtonEnable?Colors.white:Colors.black.withOpacity(0.2),       //文本顏色      color: isButtonEnable?Color(0xff44c5fe):Colors.grey.withOpacity(0.1),       //按鈕的顏色      splashColor: isButtonEnable?Colors.white.withOpacity(0.1):Colors.transparent,      shape: StadiumBorder(side: BorderSide.none),      onPressed: (){ setState(() {       _buttonClickListen();      });},//      child: Text('重新發(fā)送 (${secondSy})'),      child: Text('$buttonText',style: TextStyle(fontSize: 13,),),      ),     ),     ],    ),   ),   Container(   width: double.infinity,   height: 45,   margin: EdgeInsets.only(top: 50,left: 10,right: 10),   child: RaisedButton(    onPressed: () {    debugPrint('${mController.text}');    },    shape: StadiumBorder(side: BorderSide.none),    color: Color(0xff44c5fe),    child: Text(    '下一步',    style: TextStyle(color: Colors.white,fontSize: 15),    ),   ),   ),  ],  ), ); }}

上述就是小編為大家分享的flutter中怎么實現(xiàn)發(fā)送驗證碼功能了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章題目:flutter中怎么實現(xiàn)發(fā)送驗證碼功能
網(wǎng)頁URL:http://bm7419.com/article16/psdigg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計小程序開發(fā)、網(wǎng)站導(dǎo)航、關(guān)鍵詞優(yōu)化、微信小程序、虛擬主機

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)