Flutter 限制TextFormField输入类型

Container(
            height: 40,
            child: Row(
              textBaseline: TextBaseline.ideographic,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                MyText('新密码'),
                Expanded(
                    child: TextFormField(
                  maxLines: 1,
                  textAlign: TextAlign.right,
                  inputFormatters: [
                    WhitelistingTextInputFormatter(RegExp("[a-z,A-Z,0-9]")),      //限制只允许输入字母和数字
//                    WhitelistingTextInputFormatter.digitsOnly,                //限制只允许输入数字    
//                    LengthLimitingTextInputFormatter(8),                      //限制输入长度不超过8位
                        
                  ],
                  style: TextStyle(
                    color: Color(0xff333333),
                    fontSize: 12.0,
                  ),
                  decoration: InputDecoration(
                      hintText: '字母+数字',
                      contentPadding: EdgeInsets.symmetric(vertical: 1),
                      hintStyle: TextStyle(fontSize: 12.0, color: Colors.grey),
                      border: OutlineInputBorder(borderSide: BorderSide.none)),
                )),
              ],
            ),
          )

效果如下:

你可能感兴趣的:(Flutter)