Created
April 12, 2025 11:36
-
-
Save EsinShadrach/f2e5f457430e3efc23d9485d031ddf4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class ScorePickerListView extends StatefulWidget { | |
| const ScorePickerListView({super.key}); | |
| @override | |
| State<ScorePickerListView> createState() => _ScorePickerListViewState(); | |
| } | |
| class _ScorePickerListViewState extends State<ScorePickerListView> { | |
| static const itemCount = 10; | |
| late FixedExtentScrollController fixedExtentController; | |
| int selectedIndex = 0; | |
| int getLoopedIndex(int index) => (index + itemCount) % itemCount; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| fixedExtentController = FixedExtentScrollController( | |
| initialItem: 10000 + selectedIndex, | |
| ); | |
| } | |
| @override | |
| void dispose() { | |
| fixedExtentController.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return ListWheelScrollView.useDelegate( | |
| controller: fixedExtentController, | |
| itemExtent: 50, | |
| physics: const FixedExtentScrollPhysics(), | |
| overAndUnderCenterOpacity: 0.5, | |
| perspective: 0.002, | |
| onSelectedItemChanged: (index) { | |
| setState(() { | |
| selectedIndex = getLoopedIndex(index); | |
| }); | |
| if (context.isApple) { | |
| HapticFeedback.selectionClick(); | |
| } | |
| }, | |
| childDelegate: ListWheelChildBuilderDelegate( | |
| childCount: 100000, | |
| builder: (context, index) { | |
| final realIndex = getLoopedIndex(index); | |
| final isSelected = realIndex == selectedIndex; | |
| return Text( | |
| realIndex.toString(), | |
| style: GoogleFonts.spaceGrotesk( | |
| fontSize: 34, | |
| fontWeight: FontWeight.bold, | |
| color: | |
| isSelected | |
| ? context.colorScheme.onSurface | |
| : context.colorScheme.outline, | |
| ), | |
| ).centered; | |
| }, | |
| ), | |
| ).withConstraints(maxHeight: 130, maxWidth: 50); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment