Home > Enterprise >  how to get the index of clicked element in flutter?
how to get the index of clicked element in flutter?

Time:08-09

I have a list and I want to navigate between questions by clicking on the element like in the picture picture of elements ...another usage I think if I can get the Text of clicked and convert it then use it as index it will work but idk how or if there is a better way to do it thanks

List<Widget> _scoreTracker = [];
. 
.
.
_scoreTracker.add(
        answerScore
            ?
          GestureDetector(
                onTap: (){
                  if (endOfQuiz)
                    {

                     setState(() {
                       rev = true;
                       _questionIndex = **_scoreTrackerIndex;**

                     });
                    }
                },
                child: Container(
                  child: Center(
                    child: Text("${_questionIndex 1}",
    
            

CodePudding user response:

Before _scoreTracker.add( line

do

final int btnIndex  = _scoreTracker.toList().length-1 ;

_scoreTracker.add(
        answerScore
       .....
        _questionIndex = btnIndex  ;
  • Related