Flutter的TextField

TextField(
                decoration: const InputDecoration(
                    border: OutlineInputBorder(
                        borderSide:
                            const BorderSide(color: Colors.orangeAccent),
                        borderRadius:
                            const BorderRadius.all(Radius.circular(3))),
                    labelText: "用户名",
                    labelStyle: TextStyle(color: Colors.orangeAccent),
                    floatingLabelBehavior: FloatingLabelBehavior.auto,
                    //always、never
                    helperText: "用户名的长度为3~6个汉字",
                    helperStyle: TextStyle(color: Colors.grey),
                    helperMaxLines: 1,
                    hintText: "请输入用户名",
                    hintStyle: TextStyle(color: Colors.grey),
                    errorText: "用户名输入有误",
                    errorStyle: TextStyle(color: Colors.redAccent),
                    errorBorder: OutlineInputBorder(
                        borderSide: const BorderSide(color: Colors.redAccent),
                        borderRadius:
                            const BorderRadius.all(Radius.circular(3))),
                    suffixIcon: Icon(Icons.favorite),
                    fillColor: Colors.black12,
                    filled: true,
                    icon: Icon(
                      Icons.person,
                      color: Colors.orangeAccent,
                    ),
                    prefixIcon: Icon(
                      Icons.edit,
                      color: Colors.orangeAccent,
                    ),
                    focusColor: Colors.orangeAccent),
                controller: _editingController,
                //Controller
                keyboardType: TextInputType.text,
                //键盘输入类型
                textInputAction: TextInputAction.done,
                textCapitalization: TextCapitalization.none,
                //键盘的字母默认大小写
                toolbarOptions: ToolbarOptions(
                    copy: true, cut: true, paste: true, selectAll: true),
                //弹出菜单选项,选择、复制粘贴、剪切
                cursorWidth: 1,
                //设置光标宽带
                cursorColor: Colors.orangeAccent,
                //设置光标颜色
                cursorRadius: Radius.circular(5),
                //设置光标圆角
                showCursor: true,
                //是否显示光标
                obscureText: true,
                //是否密码框
                inputFormatters: [
                  //输入的字符白名单
                  WhitelistingTextInputFormatter(RegExp("[0-9]"))
                ],
                onChanged: (value) {
                  //内容变化事件
                  print(value);
                },
                onEditingComplete: () {
                  //点击done 后,触发
                  print(_editingController.text);
                },
                onTap: () {
                  print("点击了");
                },
                maxLength: 10,
                buildCounter: (BuildContext context,
                    {int currentLength, bool isFocused, int maxLength}) {
                  return Text("$currentLength/$maxLength"); //字符统计
                },
              )
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容