赞
踩
import 'package:flutter/services.dart';
TextField(
keyboardType: TextInputType.number,
),
输入的类型
TextField(
keyboardType: TextInputType.number,//键盘类型,数字键盘
style: TextStyle(fontSize: ScreenUtil().setWidth(40), color: Colors.black),//输入文字样式
controller: _cpyCode,//控制器
decoration: InputDecoration(
hintText: '请输入6位公司编号',
hintStyle: TextStyle( fontWeight: FontWeight.w600, fontSize: ScreenUtil().setWidth(40), color: Colors.grey[400]),
border: InputBorder.none,
),
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,//只输入数字
LengthLimitingTextInputFormatter(6)//限制长度
],
onChanged: _listenCpyCode,
)),
小数校验
class _UsNumberTextInputFormatter extends TextInputFormatter { static const defaultDouble = 0.001; static double strToFloat(String str, [double defaultValue = defaultDouble]) { try { return double.parse(str); } catch (e) { return defaultValue; } } @override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { String value = newValue.text; int selectionIndex = newValue.selection.end; if (value == ".") { value = "0."; selectionIndex++; } else if (value != "" && value != defaultDouble.toString() && strToFloat(value, defaultDouble) == defaultDouble) { value = oldValue.text; selectionIndex = oldValue.selection.end; } return new TextEditingValue( text: value, selection: new TextSelection.collapsed(offset: selectionIndex), ); } }
resizeToAvoidBottomPadding: false,
FocusScope.of(context).requestFocus(FocusNode());
inputFormatters: [
WhitelistingTextInputFormatter(RegExp(
"[a-zA-Z]|[\u4e00-\u9fa5]|[0-9]")), //只能输入汉字或者字母或数字
LengthLimitingTextInputFormatter(maxLength),//最大长度
],
void main(){
// 强制横屏
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight
]);
runApp(new MyApp());
}
void main(){
// 强制竖屏
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(new MyApp());
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。