flutter listView不会刷新自己
当我按“绿色”按钮时,这意味着“添加学生”的应用程序将进入一个页面,其中包含以下输入按钮。
当我按“ kaydet”时,这意味着保存它不会将学生添加到listView中。但是当我单击某些东西时,学生会出现。我该如何弄清楚。
下面的代码。
Expanded(
child: ListView.builder(
itemCount: students.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(students[index].profilePhoto),
),
title: Text(
students[index].firstName + " " + students[index].lastName),
subtitle: Text("Sınavdan aldığı not: " +
students[index].grade.toString() +
" [" +
students[index].getStatus +
"]"),
trailing: buildStatusIcon(students[index].grade),
onTap: () {
setState(() {
selectedStudent = students[index];
});
},
);
},
),
),
和其他文件
Widget buildSubmitButton() {
return ElevatedButton(
child: const Text("Kaydet"),
onPressed: () {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
students!.add(student);
Navigator.pop(context);
}
},
);
}
i have an app like this. When i press the green button which means "add student" my app goes to a page which includes input buttons like below.
when I press "Kaydet" which mean save it doesn't add the student into the listview. But when I click something the student appears. How can I figure it.
The codes below.
Expanded(
child: ListView.builder(
itemCount: students.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(students[index].profilePhoto),
),
title: Text(
students[index].firstName + " " + students[index].lastName),
subtitle: Text("Sınavdan aldığı not: " +
students[index].grade.toString() +
" [" +
students[index].getStatus +
"]"),
trailing: buildStatusIcon(students[index].grade),
onTap: () {
setState(() {
selectedStudent = students[index];
});
},
);
},
),
),
and other file
Widget buildSubmitButton() {
return ElevatedButton(
child: const Text("Kaydet"),
onPressed: () {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
students!.add(student);
Navigator.pop(context);
}
},
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在“添加学生”按钮中使用navigator.push,有一个.navigator。
I think you use a Navigator.push in your 'add student' button ,there is a .then property for Navigator.push, try to use a setState hear