【发布时间】:2019-12-10 14:21:31
【问题描述】:
我正在尝试更新 ListView 在添加按钮的 onPressed 函数中,我使用 setState 函数在待办事项列表中添加了新的待办事项。但在android上它不起作用。在 iOS 上它工作正常。
ListView.builder(
itemCount: todos.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 1.0, horizontal: 4.0),
child: Card(
child: ListTile(
onTap: () {},
title: Text(todos[index].text),
),
),
);
},
);
onPressed: () async {
Todo newTodo = Todo(text: todoText);
newTodo.insert();
setState(() {
todos.add(newTodo);
});
Navigator.of(context).pop();
}
【问题讨论】: