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

你可能感兴趣的:(Flutter的TextField)