Skip to content

Instantly share code, notes, and snippets.

@mbaka-bilal
Created December 8, 2023 01:54
Show Gist options
  • Save mbaka-bilal/42db307c21404afc116da54c7f762d7d to your computer and use it in GitHub Desktop.
Save mbaka-bilal/42db307c21404afc116da54c7f762d7d to your computer and use it in GitHub Desktop.
slide or tap to rate
Widget SlideOrTapToRate(){
return SizedBox(
width: 400,
child: GestureDetector(
onHorizontalDragStart: (dragStart) {
setState(() {
offset = 0;
selectedStar = -1;
});
},
onHorizontalDragUpdate: (dragUpdateDetails) {
setState(() {
offset = offset +
dragUpdateDetails.primaryDelta! / 50;
selectedStar = offset.clamp(-1, 5);
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
...List.generate(
5,
(index) => GestureDetector(
onTap: () {
setState(() {
if (index == 0 &&
selectedStar == 0) {
selectedStar = -1;
} else {
selectedStar = index;
}
});
},
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 8.0),
child: Image.asset(AppImages.star,
color: (index <= selectedStar)
? AppColors.primaryColor
: null),
),
)),
],
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment