flutter 表单组件TextField、TextFormField使用

属性介绍

属性 说明
controller 控制器,可以控制 textField 的输入内容,也可以监听 textField 改变
focusNode 焦点控制,
decoration textField 装饰
keyboardType TextInputType,键盘类型
textCapitalization 大小写,默认为 TextCapitalization.none
style 字体样式
strutStyle 字体的布局样式
textAlign 文字对齐方式,默认为 TextAlign.start
textAlignVertical 文字纵轴对齐方式
textDirection TextDirection.ltr 是居左,TextDirection.rtl 是居右,和 textAlign 效果一致
readOnly 只读属性,默认为 false
toolbarOptions 长按时弹出的按钮设置,(如赋值,粘贴,全部选中等)
showCursor 是否显示光标,默认为 true
autofocus 是否自动聚焦,默认为 false
obscuringCharacter 加密输入时的替换字符,默认为 ‘•’
obscureText 是否加密,默认为 false
autocorrect 是否自动更正,默认为 true
smartDashesType SmartDashesType 智能替换破折号,例如连续输入三个’-’ 会自动替换成一个’——',当 obseretext == true 时,smartDashesType 默认不可用
smartQuotesType SmartQuotesType 智能替换引号,根据文字情况智能替换为左引号或者右引号,当 obseretext == true 时,SmartQuotesType 默认不可用
enableSuggestions 是否在用户输入时显示输入建议,此标志仅影响Android,默认为 true
maxLines 最大行数
minLines 最小行数
expands 是否填充父控件,默认为 false
maxLength 最大长度
maxLengthEnforced 是否强制限制,或者只提供字符计数器和警告,默认为 true
onChanged 输入框文字改变回调
onEditingComplete 输入框完成回调
onSubmitted 提交按钮点击回调
inputFormatters 格式化输入,注意这里比 onChanged 先执行
enabled 是否可用
cursorWidth 光标宽度,默认为 2.0
cursorRadius 光标圆角
cursorColor 光标颜色
selectionHeightStyle 选中高度样式,默认为 ui.BoxHeightStyle.tight
keyboardAppearance 键盘外观,此设置仅适用于iOS设备,iOS的白色以及黑色风格键盘
scrollPadding 滚动后距离边缘的距离,默认为 EdgeInsets.all(20.0)
dragStartBehavior 启动阻力,默认为 DragStartBehavior.start
enableInteractiveSelection ///默认为True,如果为false,则大多数辅助功能支持选择文本、复制和粘贴,移动插入符号将被禁用。
onTap 点击事件
mouseCursor 鼠标悬停,Web可以了解
buildCounter InputDecorator.counter 自定义小工具
scrollController 滚动控制器
scrollPhysics 滚动物理效果
autofillHints 自动填充

示例代码

     children: [
        const Text("提货点:"),
        //这里只能写在容器container中才可以
        Container(
           width: 500.w,
          child: TextField(
          decoration: const InputDecoration(hintText: "请输入提货点",
            // border: OutlineInputBorder(),
            // 取消自带的下边框
                // border: InputBorder.none,
                // 底部下边框
            enabledBorder:  UnderlineInputBorder(
                  borderSide: BorderSide(color: Color.fromRGBO(235, 229, 229, 1),width: 1),
                
                ),
            // 选中时候下边框
            focusedBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Color.fromRGBO(228, 225, 225, 1),width: 1)
                )
          ),
          controller:_username, //默认显示的文字
          onChanged: (value){
            setState((){
              thText=value;
            });
            print("提货点名称$thText");
          },
        )
        )
        
      ],
    )

相关推荐

  1. flutter 组件TextField、TextFormField使用

    2023-12-26 17:04:03       43 阅读
  2. React - 组件实现

    2023-12-26 17:04:03       39 阅读
  3. React 组件实现

    2023-12-26 17:04:03       41 阅读
  4. 【React】React组件

    2023-12-26 17:04:03       20 阅读
  5. 微信小程序uni-app:常用Form组件使用示例

    2023-12-26 17:04:03       46 阅读
  6. Ant Design Vue组件a-form-item-rest使用

    2023-12-26 17:04:03       41 阅读
  7. 封装Element-Plus组件

    2023-12-26 17:04:03       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-26 17:04:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-26 17:04:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-26 17:04:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-26 17:04:03       20 阅读

热门阅读

  1. 开发环境和生产环境的区别

    2023-12-26 17:04:03       32 阅读
  2. 【ARM 嵌入式 编译系列 10.4 -- 生成二进制文件】

    2023-12-26 17:04:03       34 阅读
  3. 视觉SLAM十四讲|【二】李群与李代数

    2023-12-26 17:04:03       30 阅读
  4. Git 的基本概念和使用方式

    2023-12-26 17:04:03       38 阅读
  5. docker-compose 安装gitlab

    2023-12-26 17:04:03       44 阅读
  6. Verilog 14: 阻塞和非阻塞赋值的异同

    2023-12-26 17:04:03       30 阅读
  7. 【Netty】案例-群聊天室实现

    2023-12-26 17:04:03       30 阅读