Flutter ListView Item Click Listener

When adding the onTap for your GestureRecognizer, (or button), your closure can capture the index passed through in the itemBuilder.

E.g.

 body: ListView.builder(
            itemBuilder: (BuildContext context, int index) {
              return GestureDetector(
                child: Text(index.toString()),
                onTap: () => Scaffold
                    .of(context)
                    .showSnackBar(SnackBar(content: Text(index.toString()))),
              );
            },
            itemCount: 10));

This code will display a snack bar containing the index of the ListItem that you have tapped.

Once you have the index of the item, you can navigate to a new page using code provided by other answers to this question.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)