0

I am trying to implement a search function in GridView, which is on SimpleDialog. When I perform a search, the GridView is not updating. But when I scroll through GridView, It updates.

Below is my code

Widget _showParentCategory() {
    return SimpleDialog(
      children: [
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 10.0),
          child: TextField(
            onChanged: (value) {
              finalList = myProducts
                  .where((product) => product["name"]
                      .toString()
                      .toLowerCase()
                      .contains(value.toLowerCase()))
                  .toList();
              setState(() {
                finalList;
              });
            },
            decoration: const InputDecoration(suffixIcon: Icon(Icons.close)),
          ),
        ),
        const SizedBox(
          height: 20,
        ),
        SizedBox(
          height: MediaQuery.of(context).size.height * 0.7,
          width: MediaQuery.of(context).size.width,
          child: Container(
            color: Colors.white,
            child: GridView.builder(
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 3,
                  crossAxisSpacing: 5.0,
                  mainAxisSpacing: 5.0),
              itemCount: finalList.length,
              itemBuilder: (BuildContext context, index) {
                return Column(
                  children: [
                    const CircleAvatar(
                      backgroundColor: Colors.red,
                      radius: 20.0,
                    ),
                    Text(finalList[index]["name"])
                  ],
                );
              },
            ),
          ),
        )
      ],
    );
  }

I tried to print my finalist which is getting updated but it seems setState is not working. How can I redraw/ refresh GridView?

Lalit Chattar
  • 1,914
  • 8
  • 27
  • 49
  • You should be able to find the answer here: https://stackoverflow.com/questions/51962272/how-to-refresh-an-alertdialog-in-flutter – Ber Jan 19 '22 at 16:15
  • Does this answer your question? [How to refresh an AlertDialog in Flutter?](https://stackoverflow.com/questions/51962272/how-to-refresh-an-alertdialog-in-flutter) – Ber Jan 19 '22 at 16:15

0 Answers0