我想将用户写入容器中TextField的数据显示为Text。在接收数据时,我给Container一个恒定的高度,并为TextField设置maxLines:10000,这样用户在不溢出Container的情况下写入,文本就会在Container内向上移动。有没有一种结构可以用这种方式显示输出用户数据?当我尝试以同样的方式显示输出时,它不会显示溢出的文本,我如何使其可滚动?
这里是用户数据接收代码:
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
),
child: Container(
height: MediaQuery.of(context).size.height * 7 / 10,
decoration: BoxDecoration(
border: Border.all(
color: UserColorHelper.Blue,
width: 1,
),
borderRadius: BorderRadius.circular(4),
),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: TextField(
decoration: InputDecoration.collapsed(
hintText: "Note here..."),
style: TextStyle(color: UserColorHelper.Light),
keyboardType: TextInputType.text,
maxLines: 10000,
textInputAction: TextInputAction.done,
autofocus: false,
onEditingComplete: () {},
),
),
),
),
文本_输入
使用TextEditingController
添加
controller: reasonController,
将您的代码修复为:
final reasonController = TextEditingController();
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
),
child: Container(
height: MediaQuery.of(context).size.height * 7 / 10,
decoration: BoxDecoration(
border: Border.all(
color: UserColorHelper.Blue,
width: 1,
),
borderRadius: BorderRadius.circular(4),
),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: TextField(
controller: reasonController,
decoration: InputDecoration.collapsed(
hintText: "Note here..."),
style: TextStyle(color: UserColorHelper.Light),
keyboardType: TextInputType.text,
maxLines: 10000,
textInputAction: TextInputAction.done,
autofocus: false,
onEditingComplete: () {
print(reasonController.text);
},
),
),
),
),
从控制器获取文本
print(reasonController.text)
您可以使用textfield((的溢出属性,这样做,
overflow: TextOverflow.ellipsis,
或
overflow: TextOverflow.fade,