Instantly share code, notes, and snippets.

Embed
What would you like to do?
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