赞
踩
/** * @Title: * @Package * @Description: (用一句话描述该文件做什么) * @author A18ccms A18ccms_gmail_com * @date * @version V1.0 */ import 'package:flutter/material.dart'; import 'package:fluttertestdemo/services/ScreenAdapter.dart'; class RecycleKeyboardPage extends StatefulWidget { @override RecycleKeyboardPageState createState() => new RecycleKeyboardPageState(); } class RecycleKeyboardPageState extends State<RecycleKeyboardPage> { //用户名输入框控制器 此控制器可以监听用户名输入框的操作 TextEditingController _telephoneController=new TextEditingController(); //表单状态 GlobalKey<FormState> _formKey=GlobalKey<FormState>(); var _isShowClear=false; // 是否显示输入框尾的清除按钮 var tel=''; /* * 验证手机号 */ String validateTelePhone(value) { RegExp exp=RegExp(r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$'); if(value.isEmpty){ return '手机号不能为空'; }else if (!exp.hasMatch(value)){ return '请输入正确手机号'; } return null; } @override Widget build(BuildContext context) { ScreenAdapter.init(context); return new Scaffold( appBar: new AppBar( centerTitle: true, title: new Text('新用户注册'), leading: IconButton( icon: Icon(Icons.keyboard_arrow_left,), onPressed: () { }, ), ), body: GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { print("点击了空白区域"); // _focusNodeTelephone.unfocus(); FocusScope.of(context).requestFocus(FocusNode()); }, child: Container( padding: EdgeInsets.all(ScreenAdapter.width(50)), child: ListView( children: <Widget>[ SizedBox(height: 60,), Form( key: _formKey, child: TextFormField( controller: _telephoneController, keyboardType: TextInputType.number, decoration: InputDecoration( hintText: "请输入密码", border: InputBorder.none, suffixIcon: (_isShowClear)?IconButton( icon: Icon(Icons.clear), onPressed: () { _telephoneController.clear(); }, ):null, ), // 验证手机号码 validator: validateTelePhone, //保存手机号码 onSaved: (String value) { this.tel=value; }, ), ), SizedBox( height: 40, ), RaisedButton( child: Text("下一步"), color: Colors.deepOrange, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20), ), onPressed: () { }, ) ], ), ), ) ); } @override void initState() { // TODO: implement initState super.initState(); //设置焦点监听 // _focusNodeTelephone.addListener(_focusNodeListener); // 监听手机号的输入改变 _telephoneController.addListener(() { print(_telephoneController.text); //监听文本框输入变化,当有内容的时候,显示尾部清除按钮,否则不显示 if(_telephoneController.text.length>0) { _isShowClear=true; }else{ _isShowClear=false; } setState(() { }); }); } @override void dispose() { // TODO: implement dispose super.dispose(); _telephoneController.dispose(); } @override void didUpdateWidget(RecycleKeyboardPage oldWidget) { // TODO: implement didUpdateWidget super.didUpdateWidget(oldWidget); } @override void didChangeDependencies() { // TODO: implement didChangeDependencies super.didChangeDependencies(); } }
https://gitee.com/wizard-cc/flutter__test_demo.git
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。