Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
24b40d87
Commit
24b40d87
authored
Apr 25, 2017
by
Ian Hickson
Committed by
GitHub
Apr 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make getVelocity never return null (#9583)
Fixes
https://github.com/flutter/flutter/issues/8425
parent
ad1c497c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
14 deletions
+21
-14
multidrag.dart
packages/flutter/lib/src/gestures/multidrag.dart
+1
-1
scale.dart
packages/flutter/lib/src/gestures/scale.dart
+1
-1
velocity_tracker.dart
packages/flutter/lib/src/gestures/velocity_tracker.dart
+14
-12
velocity_tracker_test.dart
packages/flutter/test/gestures/velocity_tracker_test.dart
+5
-0
No files found.
packages/flutter/lib/src/gestures/multidrag.dart
View file @
24b40d87
...
@@ -123,7 +123,7 @@ abstract class MultiDragPointerState {
...
@@ -123,7 +123,7 @@ abstract class MultiDragPointerState {
assert
(
_arenaEntry
!=
null
);
assert
(
_arenaEntry
!=
null
);
if
(
_client
!=
null
)
{
if
(
_client
!=
null
)
{
assert
(
pendingDelta
==
null
);
assert
(
pendingDelta
==
null
);
final
DragEndDetails
details
=
new
DragEndDetails
(
velocity:
_velocityTracker
.
getVelocity
()
??
Velocity
.
zero
);
final
DragEndDetails
details
=
new
DragEndDetails
(
velocity:
_velocityTracker
.
getVelocity
());
final
Drag
client
=
_client
;
final
Drag
client
=
_client
;
_client
=
null
;
_client
=
null
;
// Call client last to avoid reentrancy.
// Call client last to avoid reentrancy.
...
...
packages/flutter/lib/src/gestures/scale.dart
View file @
24b40d87
...
@@ -193,7 +193,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -193,7 +193,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
assert
(
tracker
!=
null
);
assert
(
tracker
!=
null
);
Velocity
velocity
=
tracker
.
getVelocity
();
Velocity
velocity
=
tracker
.
getVelocity
();
if
(
velocity
!=
null
&&
_isFlingGesture
(
velocity
))
{
if
(
_isFlingGesture
(
velocity
))
{
final
Offset
pixelsPerSecond
=
velocity
.
pixelsPerSecond
;
final
Offset
pixelsPerSecond
=
velocity
.
pixelsPerSecond
;
if
(
pixelsPerSecond
.
distanceSquared
>
kMaxFlingVelocity
*
kMaxFlingVelocity
)
if
(
pixelsPerSecond
.
distanceSquared
>
kMaxFlingVelocity
*
kMaxFlingVelocity
)
velocity
=
new
Velocity
(
pixelsPerSecond:
(
pixelsPerSecond
/
pixelsPerSecond
.
distance
)
*
kMaxFlingVelocity
);
velocity
=
new
Velocity
(
pixelsPerSecond:
(
pixelsPerSecond
/
pixelsPerSecond
.
distance
)
*
kMaxFlingVelocity
);
...
...
packages/flutter/lib/src/gestures/velocity_tracker.dart
View file @
24b40d87
...
@@ -125,18 +125,16 @@ class _PointAtTime {
...
@@ -125,18 +125,16 @@ class _PointAtTime {
String
toString
()
=>
'_PointAtTime(
$point
at
$time
)'
;
String
toString
()
=>
'_PointAtTime(
$point
at
$time
)'
;
}
}
/// Computes a pointer's velocity based on data from
PointerMove
events.
/// Computes a pointer's velocity based on data from
[PointerMove]
events.
///
///
/// The input data is provided by calling addPosition(). Adding data
/// The input data is provided by calling [addPosition]. Adding data is cheap.
/// is cheap.
///
///
/// To obtain a velocity, call [getVelocity] or [getVelocityEstimate].
/// To obtain a velocity, call [getVelocity] or [getVelocityEstimate]. This will
/// This will compute the velocity based on the data added so far. Only
/// compute the velocity based on the data added so far. Only call these when
/// call this when you need to use the velocity, as it is comparatively
/// you need to use the velocity, as they are comparatively expensive.
/// expensive.
///
///
/// The quality of the velocity estimation will be better if more data
/// The quality of the velocity estimation will be better if more data
points
///
points
have been received.
/// have been received.
class
VelocityTracker
{
class
VelocityTracker
{
static
const
int
_kAssumePointerMoveStoppedMilliseconds
=
40
;
static
const
int
_kAssumePointerMoveStoppedMilliseconds
=
40
;
static
const
int
_kHistorySize
=
20
;
static
const
int
_kHistorySize
=
20
;
...
@@ -157,6 +155,10 @@ class VelocityTracker {
...
@@ -157,6 +155,10 @@ class VelocityTracker {
/// Returns an estimate of the velocity of the object being tracked by the
/// Returns an estimate of the velocity of the object being tracked by the
/// tracker given the current information available to the tracker.
/// tracker given the current information available to the tracker.
///
/// Information is added using [addPosition].
///
/// Returns null if there is no data on which to base an estimate.
VelocityEstimate
getVelocityEstimate
()
{
VelocityEstimate
getVelocityEstimate
()
{
final
List
<
double
>
x
=
<
double
>[];
final
List
<
double
>
x
=
<
double
>[];
final
List
<
double
>
y
=
<
double
>[];
final
List
<
double
>
y
=
<
double
>[];
...
@@ -228,12 +230,12 @@ class VelocityTracker {
...
@@ -228,12 +230,12 @@ class VelocityTracker {
///
///
/// This can be expensive. Only call this when you need the velocity.
/// This can be expensive. Only call this when you need the velocity.
///
///
///
getVelocity() will return null if no estimate is available or if
///
Returns [Velocity.zero] if there is no data from which to compute an
///
the
velocity is zero.
///
estimate or if the estimated
velocity is zero.
Velocity
getVelocity
()
{
Velocity
getVelocity
()
{
final
VelocityEstimate
estimate
=
getVelocityEstimate
();
final
VelocityEstimate
estimate
=
getVelocityEstimate
();
if
(
estimate
==
null
||
estimate
.
pixelsPerSecond
==
Offset
.
zero
)
if
(
estimate
==
null
||
estimate
.
pixelsPerSecond
==
Offset
.
zero
)
return
null
;
return
Velocity
.
zero
;
return
new
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
);
return
new
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
);
}
}
}
}
packages/flutter/test/gestures/velocity_tracker_test.dart
View file @
24b40d87
...
@@ -71,4 +71,9 @@ void main() {
...
@@ -71,4 +71,9 @@ void main() {
}
}
}
}
});
});
test
(
'No data velocity estimation'
,
()
{
final
VelocityTracker
tracker
=
new
VelocityTracker
();
expect
(
tracker
.
getVelocity
(),
Velocity
.
zero
);
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment