scroll
This commit is contained in:
parent
d8f73a3c38
commit
609317bc35
@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
@ -76,6 +77,39 @@ class _SwipeQuestionTileState extends State<SwipeQuestionTile>
|
||||
double get _snappedVerticalOffset =>
|
||||
_snappedSliderValue / _sliderMax * _maxVerticalDrag;
|
||||
|
||||
void _applyVerticalInputDelta(double dy) {
|
||||
setState(() {
|
||||
_verticalOffset -= dy;
|
||||
_verticalOffset = _verticalOffset.clamp(
|
||||
-_maxVerticalDrag,
|
||||
_maxVerticalDrag,
|
||||
);
|
||||
if (_atZero) {
|
||||
_dragOffset = 0;
|
||||
}
|
||||
_maybeTriggerSnapFeedback(_snappedSliderValue);
|
||||
});
|
||||
}
|
||||
|
||||
/// One wheel notch / trackpad tick → one integer on the [-10, 10] scale.
|
||||
void _stepSliderFromScroll(double scrollDy) {
|
||||
if (scrollDy == 0) {
|
||||
return;
|
||||
}
|
||||
final int next = (_snappedSliderValue + (scrollDy > 0 ? -1 : 1))
|
||||
.clamp(_sliderMin, _sliderMax);
|
||||
if (next == _snappedSliderValue) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_verticalOffset = next / _sliderMax * _maxVerticalDrag;
|
||||
if (_atZero) {
|
||||
_dragOffset = 0;
|
||||
}
|
||||
_maybeTriggerSnapFeedback(next);
|
||||
});
|
||||
}
|
||||
|
||||
void _maybeTriggerSnapFeedback(int snapped) {
|
||||
if (snapped == _lastSnappedValue) {
|
||||
return;
|
||||
@ -216,26 +250,25 @@ class _SwipeQuestionTileState extends State<SwipeQuestionTile>
|
||||
bottom: 8,
|
||||
left: constraints.maxWidth * 0.22,
|
||||
right: constraints.maxWidth * 0.22,
|
||||
child: Listener(
|
||||
onPointerSignal: (PointerSignalEvent event) {
|
||||
if (widget.busy || _acting) {
|
||||
return;
|
||||
}
|
||||
if (event is PointerScrollEvent) {
|
||||
_stepSliderFromScroll(
|
||||
event.scrollDelta.dy,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onVerticalDragUpdate: widget.busy || _acting
|
||||
? null
|
||||
: (DragUpdateDetails details) {
|
||||
setState(() {
|
||||
_verticalOffset -= details.delta.dy;
|
||||
_verticalOffset =
|
||||
_verticalOffset.clamp(
|
||||
-_maxVerticalDrag,
|
||||
_maxVerticalDrag,
|
||||
);
|
||||
if (_atZero) {
|
||||
_dragOffset = 0;
|
||||
}
|
||||
_maybeTriggerSnapFeedback(
|
||||
_snappedSliderValue,
|
||||
);
|
||||
});
|
||||
},
|
||||
: (DragUpdateDetails details) =>
|
||||
_applyVerticalInputDelta(
|
||||
details.delta.dy,
|
||||
),
|
||||
child: Center(
|
||||
child: Transform.translate(
|
||||
offset:
|
||||
@ -249,6 +282,7 @@ class _SwipeQuestionTileState extends State<SwipeQuestionTile>
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user