Home > Software engineering >  Flutter ListView doesn't refreshing itself
Flutter ListView doesn't refreshing itself

Time:07-07

enter image description here

enter image description here

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);
        }
      },
    );
  }

CodePudding user response:

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

Navigator.push(context,route).then((value) {
                        setState(() {});
                      });
  • Related