Using builTextField() method to create textField, passing different controller.
TextEditingController phoneController;
TextEditingController otpController;
builTextField(phoneController),
builTextField(otpController),
使用 phoneController.text 和 otpController.text 为各自的 textField 填充hintText。
相似地,
using buildRaisedButton() method to create Button, passing differetnt callback.
buildRaisedButton('Register', registrationCallback),
buildRaisedButton('Verify', verifyOTPCallback),
buildRaisedButton('Reset',resetCallback),
在按钮上单击“重置”,想要清除两个文本字段的 hitText
resetCallback(){
print('cleared ....');
setState(() {
phoneController.clear();
otpController.clear();
});
}
看起来 controller.clear 正在将 conroller.text 值重置为 empty(''),但由于hintText 的值被选择为 conroller.text,因此也应该在屏幕中更新为“empty”。但不幸的是,它没有反映在 UI 中,尽管将代码包装在 setState() 中
构建文本字段()
Widget buildTextField(TextEditingController controller, ) {
return Container(
height: 40.0,
width: 200.0,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(32),
),
child: TextField(
keyboardType: TextInputType.number,
style: kPhoneAuthTextFields,
decoration: InputDecoration(
hintStyle: kPhoneAuthTextFields,
hintText:controller.text,
suffixIcon: Icon(Icons.phone_android,size: 20,color: Colors.white,),
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 5.0, left: 30.0),
),
onChanged: (value) {
controller.text = value;
},
),
);
}
buildRaisedButton()
Widget buildRaisedButton(String label, Function callback){
return Container(
height: 40.0,
width: 100.0,
child: RaisedButton(
child:Text(
label,
style: kPhoneLoginTextStyle,
),
color: Colors.blue,
//padding: EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40.0)),
onPressed: callback,
),
);
}
任何帮助,不胜感激......在此先感谢......