SMSコードを送信Flutter-

 

 

 

 

インポート「ダーツ:非同期」;

インポート 'パッケージ:フラッター/ material.dart' ;
インポート 'パッケージ:フラッター/ services.dart' ;

クラスを作成拡張StatefulWidgetを{
  @オーバーライド
  _CreateState createState() => _CreateState();
}

クラス _CreateStateは、拡張状態は、<作成> {
  @オーバーライド
  ウィジェットビルド(BuildContextコンテキスト){
    リターン足場(
      アプリケーションバー:アプリケーションバー(
        タイトル:テキスト(「携帯電話のアカウント登録」)、
      )、
      ボディ:センター(
        子:はmyBody()、
      )、
    );
  }
}

クラスはmyBodyは延びStatefulWidgetを{
  @オーバーライド
  _MyBodyState createState() => _MyBodyState();
}

クラス _MyBodyStateは延び <はmyBody>状態の{
  isButtonEnable BOOL = trueに ;   // クリック可能なボタンであれば 
  文字列buttonText = '送信コード'; // 最初のテキスト
  int型 COUNT = 60;       // 初期カウントダウン時間 
  タイマタイマ;       // カウントダウンタイマー 
  TextEditingController mController = TextEditingController() ;
  TextEditingController phoneController = TextEditingController()。

  ボイド_buttonClickListen(){
    SETSTATE((){
      IF(isButtonEnable){    // ときにクリック可能なボタン 
        isButtonEnable = falseに ; // ボタンの状態フラグ
        _initTimer();
         戻り NULL ;    // 戻りNULL禁止ボタンクリック 
      }  {      // ボタンがクリックされていない場合
 //   (debugPrint 'をfalseに「); 
        リターン ヌル ;     // nullを返し禁止ボタンクリック
      }
    });
  }


  ボイド_initTimer(){
    H = 新しい Timer.periodic(時間(秒:1 )、(HOURS時間){
      カウント - ;
      SETSTATE((){
        場合(== 0をカウント{)
          timer.cancel();     // カウントダウンタイマーは取り消され 
          isButtonEnable = trueに ;   // クリック可能なボタン 
          COUNT = 60;      // リセット時間 
          buttonText = '送信コード';   // リセットボタンテキスト 
        } {
          buttonText = '再送信($ COUNT'); // 更新テキスト
        }
      });
    });
  }


  @オーバーライド
  ボイド廃棄(){
    タイマー .cancel();?   // タイマーを破壊する 
    タイマー= ヌル;
     スーパー.Disposeを();
  }


  @オーバーライド
  ウィジェットビルド(BuildContextコンテキスト){
    リターンコンテナ(
      子供:列(
//   mainAxisAlignment:MainAxisAlignment.center、 
        子供:<ウィジェット> [
          容器(
            色:Colors.white、
            パディングは:EdgeInsets.only(左: 10、右:10 )、
            子供:列(
              子供: <ウィジェット> [
                行(
                  mainAxisAlignment:MainAxisAlignment.spaceBetween、
//      crossAxisAlignment:CrossAxisAlignment.center、
                  crossAxisAlignment:CrossAxisAlignment.baseline、
                  テキストのベースライン:TextBaseline.ideographic、
                  子供: <ウィジェット> [
                    テキスト( '手機號'スタイル:TEXTSTYLE(のfontSize:13、カラー:カラー(0xff333333 ))、)、
                    拡張(
                      子供:パディング(パディング:EdgeInsets.only(左: 15、右:15、トップ:15 )、
                        子供:TextFormField(
                          MAXLINES: 1 
                          onSaved:(値){}、
                          コントローラ:phoneController、
                          テキスト整列:TextAlign.LEFTに、
                          inputFormatters:[WhitelistingTextInputFormatter.digitsOnly、LengthLimitingTextInputFormatter( 6 )]、
                          装飾:InputDecoration(
                            hintTextは:(「電話番号を記入します」、)
                            contentPadding:EdgeInsets.only(トップ: -5、底:0 )、
                            hintStyle:TEXTSTYLE(
                              色:カラー( 0xff999999 
                              fontSize: 13 
                            )、
                            alignLabelWithHint:
                            ボーダー:OutlineInputBorder(borderSide:BorderSide.none)、
                          )、
                        )、)、
                    )、
                  ]、
                )、
                行(
                  mainAxisAlignment:MainAxisAlignment.spaceBetween、
//      crossAxisAlignment:CrossAxisAlignment.center、
                  crossAxisAlignment:CrossAxisAlignment.baseline、
                  テキストのベースライン:TextBaseline.ideographic、
                  子供: <ウィジェット> [
                    テキスト( '驗證碼'スタイル:TEXTSTYLE(のfontSize:13、カラー:カラー(0xff333333 ))、)、
                    拡張(
                      子供:パディング(パディング:EdgeInsets.only(左: 15、右:15、トップ:15 )、
                        子供:TextFormField(
                          MAXLINES: 1 
                          onSaved:(値){}、
                          コントローラ:mController、
                          テキスト整列:TextAlign.LEFTに、
                          inputFormatters:[WhitelistingTextInputFormatter.digitsOnly、LengthLimitingTextInputFormatter( 6 )]、
                          装飾:InputDecoration(
                            hintText:( '塗りつぶしコード' )、
                            contentPadding:EdgeInsets.only(トップ: -5、底:0 )、
                            hintStyle:TEXTSTYLE(
                              色:カラー( 0xff999999 
                              fontSize: 13 
                            )、
                            alignLabelWithHint:
                            ボーダー:OutlineInputBorder(borderSide:BorderSide.none)、
                          )、
                        )、)、
                    )、
                    容器(
                      幅: 120 
                      子供:FlatButton(
                        disabledColor:Colors.grey.withOpacity( 0.1)、   // 色ボタンが無効になっている 
                        disabledTextColor:Colors.white、      // テキストの色ボタンが無効になっている 
                        の、textColor:isButtonEnable Colors.white :? Colors.black.withOpacity(0.2)        / / 文字色 
                        カラー:? isButtonEnable色(0xff44c5fe):Colors.grey.withOpacity(0.1)、        // ボタンの色 
                        splashColor :? isButtonEnable Colors.white.withOpacity(0.1 ):Colors.transparent、
                        形状:StadiumBorder(側:BorderSide.none)
                        onPressed:(){SETSTATE((){
                          _buttonClickListen()。
                        });}
//       子:テキスト( '再送(secondSy $ {})')、 
                        子供:テキスト( 'buttonText $'、スタイル:TEXTSTYLE(のfontSize:13です、)、)、
                      )、
                    )、
                  ]、
                )、
              ]、
            )、
          )、
          容器(
            幅:ダブル.infinity、
            高さ: 45 
            マージン:EdgeInsets.only(上: 50、左:10、右:10 )、
            子供:RaisedButton(
              onPressed:(){
                debugPrint( '電話番号:$ {phoneController.text}コード:{mController.text $}' );
              }、
              形状:StadiumBorder(側:BorderSide.none)
              色:カラー( 0xff44c5fe 
              子供:テキスト(
                「登録」
                スタイル:TEXTSTYLE(色:Colors.white、fontSizeを: 15 )、
              )、
            )、
          )、
        ]、
      )、
    );
  }
}

おすすめ

転載: www.cnblogs.com/ssjf/p/12072315.html