flutter 手机号码自动输入
class _LoginMailState extends State<resetPassword> {
final arguments;
_LoginMailState({this.arguments});
//---缓存数据(声明控制器)---
TextEditingController _mobile = new TextEditingController();
static Map phone = {
"value": null,
"verify": false
};
void initState() {
super.initState();
Future.delayed(Duration.zero, () async{
prefs = await SharedPreferences.getInstance();
// startTime = prefs.getInt('startTime');
// int nowTime = G.getTime();
// if(startTime != null && startTime > 0) {
// if(nowTime - startTime > 120) {
// prefs.remove('startTime');
// } else {
// countDown();
// }
// };
//手机号缓存(----自动输入手机号----)
if (prefs != null) {
var m = prefs.getString("mobile");
if (m != null) {
_mobile.text = m;
phone = {"value": m, "verify": true};
}
}
});
}
Container(
margin: EdgeInsets.only(top: 60),
height: 55,
decoration: BoxDecoration(
border: G.borderBottom()
),
child:ARow(
height: 50,
padding: EdgeInsets.symmetric(horizontal: 5),
border: G.borderBottom(show: false),
leftChild:Text("手机号码 ",
style: TextStyle(
color: Color(0xFF1A4A7A),// rgba(85, 122, 157, 1),
fontSize: 18,)),
centerChild: TextField(
keyboardType: TextInputType.number,
controller: _mobile,//--添加控制器--
maxLength: 11,
decoration: InputDecoration(
counterText: "",
border: InputBorder.none,
hintText: '请输入手机号码',
hintStyle: TextStyle(fontSize: 17,),
),
onChanged: (e) {
RegExp regExp = RegExp("^1(3|4|5|6|7|8|9)\\d{9}");
setState(() {
if (e.length>11){e=e.substring(0,11);}
print(e);
phone['value'] = e;
phone['verify'] = regExp.hasMatch(e);
});
},
),
),
),
flutter 手机号码自动输入
最新推荐文章于 2025-05-26 11:40:09 发布