-
-
Save MarcinusX/7cc40e17cd6cce2a54650c5f7e127752 to your computer and use it in GitHub Desktop.
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
class _HeightPickerState extends State<HeightPicker> { | |
double startDragYOffset; | |
int startDragHeight; | |
... | |
return GestureDetector( | |
behavior: HitTestBehavior.translucent, | |
onTapDown: _onTapDown, | |
onVerticalDragStart: _onDragStart, | |
onVerticalDragUpdate: _onDragUpdate, | |
... | |
); | |
... | |
_onDragStart(DragStartDetails dragStartDetails) { | |
int newHeight = _globalOffsetToHeight(dragStartDetails.globalPosition); | |
widget.onChange(newHeight); | |
setState(() { | |
startDragYOffset = dragStartDetails.globalPosition.dy; | |
startDragHeight = newHeight; | |
}); | |
} | |
_onDragUpdate(DragUpdateDetails dragUpdateDetails) { | |
double currentYOffset = dragUpdateDetails.globalPosition.dy; | |
double verticalDifference = startDragYOffset - currentYOffset; | |
int diffHeight = verticalDifference ~/ _pixelsPerUnit; | |
int height = _normalizeHeight(startDragHeight + diffHeight); | |
setState(() => widget.onChange(height)); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment