This is how my code looks like:
List<Widgets> abc = [];
for(int a = 0;a<5;a++)
{
abc.add(FlatButton(onTap:(){ print(a);},
child:Text("Hello - ${a}")
)
);
}
When user clicks on "Hello - 2" Button, I want the output on console to be 2 but the output displayed is 5.
I have simplified the original problem in the form of this small programming question.I have checked a lot on internet but was unable to get any answer. Help me out please!!