Dart 颤振:Textfield初始值产生额外的新行
我需要更新卡中的值ListTile。因此,仅在longpress()中,我使用showDialog显示文本字段。文本字段的初始值在initState()中更新 以下是我的showdialog:Dart 颤振:Textfield初始值产生额外的新行,dart,flutter,textfield,Dart,Flutter,Textfield,我需要更新卡中的值ListTile。因此,仅在longpress()中,我使用showDialog显示文本字段。文本字段的初始值在initState()中更新 以下是我的showdialog: showDialog<void>( context: context, builder: (BuildContext context) { return AlertDialog( title: Text("Project Update
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Project Update"),
content: TextField(
controller: projectDetailsController,
maxLines: 100,
keyboardType: TextInputType.multiline,
),
actions: <Widget>[
FlatButton(
child: Text("UPDATE"),
onPressed: () {
_updateProjectDetails("projects/" + widget.project.documentID, projectDetailsController.text);
projectDetailsController.clear();
Navigator.pop(context);
},
),
],
);
},
);
showDialog(
上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框(
标题:文本(“项目更新”),
内容:TextField(
控制器:项目详细信息控制器,
最大行数:100,
键盘类型:TextInputType.multiline,
),
行动:[
扁平按钮(
子项:文本(“更新”),
已按下:(){
_updateProjectDetails(“projects/”+widget.project.documentID,projectDetailsController.text);
projectDetailsController.clear();
Navigator.pop(上下文);
},
),
],
);
},
);
以下是生成的showdialog:
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Project Update"),
content: TextField(
controller: projectDetailsController,
maxLines: 100,
keyboardType: TextInputType.multiline,
),
actions: <Widget>[
FlatButton(
child: Text("UPDATE"),
onPressed: () {
_updateProjectDetails("projects/" + widget.project.documentID, projectDetailsController.text);
projectDetailsController.clear();
Navigator.pop(context);
},
),
],
);
},
);
使用
maxLines:null
使文本字段自动扭曲为多行 看起来这是因为您使用了maxLines:100
。如果不设置maxLines
,则没有限制。如果需要强制执行限制,可以改用maxLength
。