【发布时间】:2021-01-14 13:03:45
【问题描述】:
TextField(
style: TextStyle(
fontFamily: "Averta",
fontWeight: FontWeight.bold,
fontSize: 16,
color: Colors.black),
enableSuggestions: true,
onChanged: (value) {
setState(() {
final title = value;
print(title);
});
},
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.all(18),
hintText: "Enter Task Title",
hintStyle: TextStyle(
fontFamily: "Averta",
fontWeight: FontWeight.normal,
fontSize: 12,
color: Colors.grey.shade300),
),
),
在这里,我有一个使用 onChanged() 函数更新的标题变量。 这里的 print() 函数显示了我在 TextField 中所做的值的精确变化。 但是我不想在这里传递它,我想获取更多数据,然后在我单击此处的 CREATE 按钮时传递它-
InkWell(
onTap: () {
print(title);
setState(() {
DatabaseHelper _dbhelper =
DatabaseHelper();
Task _newTask = Task(
title: title,
year: year,
month: month,
day: daye,
hour: hour,
minute: minute,
weekday: weekday);
_dbhelper
.insertTask(_newTask);
});
}
这里的打印语句显示“null”,但我想使用上面在 TextField 中更新的值。 如何在 Flutter 中实现这一点?
【问题讨论】:
标签: flutter variables setstate