use ChoiceChip() I also assumed the data text in the choice chip came from a backend of some sort
...
var _value = 0;
String chipCatId = "";
bool isChipSelected = false;
...
child:ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount:
snapshot.data!.data!.children!.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 2.0),
child: ChoiceChip(
backgroundColor:
AppColors.dullThemeColor,
label: Text(
index == 0
? "All"
: snapshot.data!.data!
.children![index - 1].name
.toString(),
style: const TextStyle(
color: AppColors.whiteThemeColor,
),
),
selected: _value == index,
pressElevation: 20,
elevation: 2.0,
selectedColor:
AppColors.secondaryThemeColor,
onSelected: (bool selected) {
setState(() {
chipCatId = snapshot.data!.data!
.children![index - 1].id
.toString();
isChipSelected = selected;
_value =
(selected ? index : null)!;
_onRefresh();
});
}),
);
},
);