Created
December 8, 2023 01:54
-
-
Save mbaka-bilal/42db307c21404afc116da54c7f762d7d to your computer and use it in GitHub Desktop.
slide or tap to rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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