Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created September 13, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcinusX/7cc40e17cd6cce2a54650c5f7e127752 to your computer and use it in GitHub Desktop.
Save MarcinusX/7cc40e17cd6cce2a54650c5f7e127752 to your computer and use it in GitHub Desktop.
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