Have the scale gesture callback uses details objects (#6204)

This commit is contained in:
Hans Muller
2016-10-04 12:44:36 -07:00
committed by GitHub
parent 55bc771f58
commit e2ff169d5b
5 changed files with 78 additions and 28 deletions

View File

@@ -79,21 +79,21 @@ class _GestureDemoState extends State<GestureDemo> {
bool _doubleTapEnabled = true;
bool _longPressEnabled = true;
void _handleScaleStart(Point focalPoint) {
void _handleScaleStart(ScaleStartDetails details) {
setState(() {
_startingFocalPoint = focalPoint;
_startingFocalPoint = details.focalPoint;
_previousOffset = _offset;
_previousZoom = _zoom;
});
}
void _handleScaleUpdate(double scale, Point focalPoint) {
void _handleScaleUpdate(ScaleUpdateDetails details) {
setState(() {
_zoom = (_previousZoom * scale);
_zoom = (_previousZoom * details.scale);
// Ensure that item under the focal point stays in the same place despite zooming
Offset normalizedOffset = (_startingFocalPoint.toOffset() - _previousOffset) / _previousZoom;
_offset = focalPoint.toOffset() - normalizedOffset * _zoom;
_offset = details.focalPoint.toOffset() - normalizedOffset * _zoom;
});
}