From what i know in flutter, i don’t think flutter has that widget yet. So this is what i do to get around.
I create separate listTiles or boxes or any widget of choice. And in the onpressed/onclicked property, i compared the number assigned to that widget with my global variable and if it’s true, set isSelected to true
Works everytime
int globalNum=3;
//somewhere in your widget tree
ListTile(
selected:globalNum==1?true:false,
selectedTileColor:Colors.red,
onTap:()=>globalNum=1,
),
ListTile(
selected:globalNum==2?true:false,
selectedTileColor:Colors.red,
onTap:()=>globalNum=2,
),
You can wrap your scaffold in a theme so that you don’t set the individual selectedTileColor. But for demostration this is how you’ll do it.
2
Answers
From what i know in flutter, i don’t think flutter has that widget yet. So this is what i do to get around.
I create separate listTiles or boxes or any widget of choice. And in the onpressed/onclicked property, i compared the number assigned to that widget with my global variable and if it’s true, set isSelected to true
Works everytime
You can wrap your scaffold in a theme so that you don’t set the individual selectedTileColor. But for demostration this is how you’ll do it.
If the control permits only one item at a time, it’s a Radio. See the docs for details.