TextField想要实现输入类型、长度限制需要先引入import ‘package:flutter/services.dart’;
例如
import 'package:flutter/services.dart';
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,
)),