flutterdartlistviewlistitem

In the Flutter list view , is there a way to know the number of the list item that the user is tapping?


In the Flutter list view, is there a way to know the number of the list item that the user is tapping?.

ListTile( title: Text(snapshot.data[index].quection) );


Solution

  • You just need to use the index of your ListView.builder like below

                ListView.builder(
                  itemBuilder: (context, index) => ElevatedButton(
                      onPressed: () {
                        print(index);
                      },
                      child: Text("$index")))