コード例 #1
0
        private void _handleOnScaleEnd(ScaleEndDetails details)
        {
            float magnitude = details.velocity.pixelsPerSecond.distance;

            if (magnitude < GridListDemoUtils._kMinFlingVelocity)
            {
                return;
            }
            Offset direction = details.velocity.pixelsPerSecond / magnitude;
            float  distance  = (Offset.zero & context.size).shortestSide;

            _flingAnimation = _controller.drive(new OffsetTween(
                                                    begin: _offset,
                                                    end: _clampOffset(_offset + direction * distance)
                                                    ));
            _controller.setValue(0.0f);
            _controller.fling(velocity: magnitude / 1000.0f);
        }
コード例 #2
0
        void _onScaleEnd(ScaleEndDetails scaleEndDetails)
        {
            if (this._scale > this._effectiveMaxScale)
            {
                this._scaleAndMoveToClamped(
                    targetScale: this._effectiveMaxScale,
                    this._position + this._initialPosition *
                    (this._scale - this._effectiveMaxScale) / this._initialScale);
                this._positionAnimationController.setValue(0);
                this._positionAnimationController.animateTo(1);
            }
            else if (this._scale < this._effectiveMinScale)
            {
                this._scaleAndMoveTo(targetScale: this._effectiveMinScale, targetPosition: Offset.zero);
                this._positionAnimationController.setValue(0);
                this._positionAnimationController.animateTo(1);
            }
            else
            {
                if (this._panning && scaleEndDetails.velocity != null)
                {
                    var velocity = scaleEndDetails.velocity.clampMagnitude(0, maxValue: this.widget.maxVelocity)
                                   .pixelsPerSecond;
                    var duration = velocity.distance / this.widget.deceleration;
                    velocity = this._toFractional(offset: velocity);
                    this._inertiaAnimationController.duration = TimeSpan.FromSeconds(value: duration);
                    this._positionAnimation = new OffsetTween(
                        begin: this._position,
                        this._position + velocity * duration / 2)
                                              .animate(parent: this._inertiaAnimationController);
                    this._inertiaAnimationController.setValue(0);
                    this._inertiaAnimationController.animateTo(1, curve: Curves.decelerate);
                }
            }

            this._scaleAnimationController.setValue(0);
            this._scaleAnimationController.animateTo(1);
            this._panning = false;
            this._scaling = false;
        }