Flutter TextField设置默认值默认值和光标位置

主要通过controller 实现,具体代码如下

1TextField(          //输入键盘类型 2 keyboardType: TextInputType.text, 3 autofocus: true, 4 decoration: InputDecoration( 5 border: OutlineInputBorder( 6 borderRadius: BorderRadius.circular(30), 7 borderSide: BorderSide.none), 8 ), 9 onChanged: (value) { 10 this._keyword = value; 11 }, 12 controller: TextEditingController.fromValue(TextEditingValue( 13 text: '${this._keyword == null ? "" : this._keyword}', //判断keyword是否为空 14 // 保持光标在最后 15 16 selection: TextSelection.fromPosition(TextPosition( 17 affinity: TextAffinity.downstream, 18 offset: '${this._keyword}'.length)))), 19 ),
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

【Flutter实战】输入框和表单

3.7输入框及表单Material组件库中提供了输入框组件TextField和表单组件Form。下面我们分别介绍一下。3.7.1TextFieldTextField用于文本输入,它提供了很多属性,我们先简单介绍一下主要属性的作用,然后通过几个示例来演示一下关键属性的用法。dartconstTextField({...

Flutter 修改TextField的高度,以及无边框圆角

修改TextField的高度可以通过decoration:InputDecoration的contentPadding进行修改,代码如下    newTextField(decoration:InputDecoration(contentPadding:constEdge

Extjs标悬浮在grid单元格上时,显示单元格中内容的值

{xtype:'gridcolumn',text:'名称',width:120,dataIndex:'name',editor:{xtype:'textfield',allowBlank:false,maxLength:20},renderer:function(v,m,r,i){

Flutter TextField设置默认值默认值和光标位置 - HelloWorld