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
00dcd5f4
Unverified
Commit
00dcd5f4
authored
Jul 28, 2020
by
Alexandre Ardhuin
Committed by
GitHub
Jul 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate gestures to nullsafety (#62157)
parent
1d5a9ae2
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
508 additions
and
538 deletions
+508
-538
dartdoc.dart
dev/tools/dartdoc.dart
+1
-0
gestures.dart
packages/flutter/lib/gestures.dart
+0
-2
arena.dart
packages/flutter/lib/src/gestures/arena.dart
+9
-10
binding.dart
packages/flutter/lib/src/gestures/binding.dart
+10
-11
constants.dart
packages/flutter/lib/src/gestures/constants.dart
+0
-1
converter.dart
packages/flutter/lib/src/gestures/converter.dart
+2
-4
debug.dart
packages/flutter/lib/src/gestures/debug.dart
+0
-1
drag.dart
packages/flutter/lib/src/gestures/drag.dart
+0
-1
drag_details.dart
packages/flutter/lib/src/gestures/drag_details.dart
+8
-9
eager.dart
packages/flutter/lib/src/gestures/eager.dart
+1
-2
events.dart
packages/flutter/lib/src/gestures/events.dart
+113
-114
force_press.dart
packages/flutter/lib/src/gestures/force_press.dart
+16
-17
hit_test.dart
packages/flutter/lib/src/gestures/hit_test.dart
+5
-9
long_press.dart
packages/flutter/lib/src/gestures/long_press.dart
+42
-43
lsq_solver.dart
packages/flutter/lib/src/gestures/lsq_solver.dart
+4
-3
monodrag.dart
packages/flutter/lib/src/gestures/monodrag.dart
+40
-41
multidrag.dart
packages/flutter/lib/src/gestures/multidrag.dart
+51
-52
multitap.dart
packages/flutter/lib/src/gestures/multitap.dart
+48
-51
pointer_router.dart
packages/flutter/lib/src/gestures/pointer_router.dart
+15
-16
pointer_signal_resolver.dart
...ges/flutter/lib/src/gestures/pointer_signal_resolver.dart
+6
-7
recognizer.dart
packages/flutter/lib/src/gestures/recognizer.dart
+36
-37
scale.dart
packages/flutter/lib/src/gestures/scale.dart
+45
-48
tap.dart
packages/flutter/lib/src/gestures/tap.dart
+36
-37
team.dart
packages/flutter/lib/src/gestures/team.dart
+8
-9
velocity_tracker.dart
packages/flutter/lib/src/gestures/velocity_tracker.dart
+12
-13
No files found.
dev/tools/dartdoc.dart
View file @
00dcd5f4
...
@@ -126,6 +126,7 @@ Future<void> main(List<String> arguments) async {
...
@@ -126,6 +126,7 @@ Future<void> main(List<String> arguments) async {
final
List
<
String
>
dartdocArgs
=
<
String
>[
final
List
<
String
>
dartdocArgs
=
<
String
>[
...
dartdocBaseArgs
,
...
dartdocBaseArgs
,
'--allow-tools'
,
'--allow-tools'
,
'--enable-experiment=non-nullable'
,
if
(
args
[
'json'
]
as
bool
)
'--json'
,
if
(
args
[
'json'
]
as
bool
)
'--json'
,
if
(
args
[
'validate-links'
]
as
bool
)
'--validate-links'
else
'--no-validate-links'
,
if
(
args
[
'validate-links'
]
as
bool
)
'--validate-links'
else
'--no-validate-links'
,
'--link-to-source-excludes'
,
'../../bin/cache'
,
'--link-to-source-excludes'
,
'../../bin/cache'
,
...
...
packages/flutter/lib/gestures.dart
View file @
00dcd5f4
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
/// The Flutter gesture recognizers.
/// The Flutter gesture recognizers.
///
///
/// To use, import `package:flutter/gestures.dart`.
/// To use, import `package:flutter/gestures.dart`.
...
...
packages/flutter/lib/src/gestures/arena.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'dart:async'
;
...
@@ -65,7 +64,7 @@ class _GestureArena {
...
@@ -65,7 +64,7 @@ class _GestureArena {
/// "eager winner". We look for an eager winner when closing the arena to new
/// "eager winner". We look for an eager winner when closing the arena to new
/// participants, and if there is one, we resolve the arena in its favor at
/// participants, and if there is one, we resolve the arena in its favor at
/// that time.
/// that time.
GestureArenaMember
eagerWinner
;
GestureArenaMember
?
eagerWinner
;
void
add
(
GestureArenaMember
member
)
{
void
add
(
GestureArenaMember
member
)
{
assert
(
isOpen
);
assert
(
isOpen
);
...
@@ -119,7 +118,7 @@ class GestureArenaManager {
...
@@ -119,7 +118,7 @@ class GestureArenaManager {
///
///
/// Called after the framework has finished dispatching the pointer down event.
/// Called after the framework has finished dispatching the pointer down event.
void
close
(
int
pointer
)
{
void
close
(
int
pointer
)
{
final
_GestureArena
state
=
_arenas
[
pointer
];
final
_GestureArena
?
state
=
_arenas
[
pointer
];
if
(
state
==
null
)
if
(
state
==
null
)
return
;
// This arena either never existed or has been resolved.
return
;
// This arena either never existed or has been resolved.
state
.
isOpen
=
false
;
state
.
isOpen
=
false
;
...
@@ -141,7 +140,7 @@ class GestureArenaManager {
...
@@ -141,7 +140,7 @@ class GestureArenaManager {
/// * [hold]
/// * [hold]
/// * [release]
/// * [release]
void
sweep
(
int
pointer
)
{
void
sweep
(
int
pointer
)
{
final
_GestureArena
state
=
_arenas
[
pointer
];
final
_GestureArena
?
state
=
_arenas
[
pointer
];
if
(
state
==
null
)
if
(
state
==
null
)
return
;
// This arena either never existed or has been resolved.
return
;
// This arena either never existed or has been resolved.
assert
(!
state
.
isOpen
);
assert
(!
state
.
isOpen
);
...
@@ -175,7 +174,7 @@ class GestureArenaManager {
...
@@ -175,7 +174,7 @@ class GestureArenaManager {
/// * [sweep]
/// * [sweep]
/// * [release]
/// * [release]
void
hold
(
int
pointer
)
{
void
hold
(
int
pointer
)
{
final
_GestureArena
state
=
_arenas
[
pointer
];
final
_GestureArena
?
state
=
_arenas
[
pointer
];
if
(
state
==
null
)
if
(
state
==
null
)
return
;
// This arena either never existed or has been resolved.
return
;
// This arena either never existed or has been resolved.
state
.
isHeld
=
true
;
state
.
isHeld
=
true
;
...
@@ -192,7 +191,7 @@ class GestureArenaManager {
...
@@ -192,7 +191,7 @@ class GestureArenaManager {
/// * [sweep]
/// * [sweep]
/// * [hold]
/// * [hold]
void
release
(
int
pointer
)
{
void
release
(
int
pointer
)
{
final
_GestureArena
state
=
_arenas
[
pointer
];
final
_GestureArena
?
state
=
_arenas
[
pointer
];
if
(
state
==
null
)
if
(
state
==
null
)
return
;
// This arena either never existed or has been resolved.
return
;
// This arena either never existed or has been resolved.
state
.
isHeld
=
false
;
state
.
isHeld
=
false
;
...
@@ -205,7 +204,7 @@ class GestureArenaManager {
...
@@ -205,7 +204,7 @@ class GestureArenaManager {
///
///
/// This is called by calling [GestureArenaEntry.resolve] on the object returned from [add].
/// This is called by calling [GestureArenaEntry.resolve] on the object returned from [add].
void
_resolve
(
int
pointer
,
GestureArenaMember
member
,
GestureDisposition
disposition
)
{
void
_resolve
(
int
pointer
,
GestureArenaMember
member
,
GestureDisposition
disposition
)
{
final
_GestureArena
state
=
_arenas
[
pointer
];
final
_GestureArena
?
state
=
_arenas
[
pointer
];
if
(
state
==
null
)
if
(
state
==
null
)
return
;
// This arena has already resolved.
return
;
// This arena has already resolved.
assert
(
_debugLogDiagnostic
(
pointer
,
'
${ disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting" }
:
$member
'
));
assert
(
_debugLogDiagnostic
(
pointer
,
'
${ disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting" }
:
$member
'
));
...
@@ -236,7 +235,7 @@ class GestureArenaManager {
...
@@ -236,7 +235,7 @@ class GestureArenaManager {
assert
(
_debugLogDiagnostic
(
pointer
,
'Arena empty.'
));
assert
(
_debugLogDiagnostic
(
pointer
,
'Arena empty.'
));
}
else
if
(
state
.
eagerWinner
!=
null
)
{
}
else
if
(
state
.
eagerWinner
!=
null
)
{
assert
(
_debugLogDiagnostic
(
pointer
,
'Eager winner:
${state.eagerWinner}
'
));
assert
(
_debugLogDiagnostic
(
pointer
,
'Eager winner:
${state.eagerWinner}
'
));
_resolveInFavorOf
(
pointer
,
state
,
state
.
eagerWinner
);
_resolveInFavorOf
(
pointer
,
state
,
state
.
eagerWinner
!
);
}
}
}
}
...
@@ -265,10 +264,10 @@ class GestureArenaManager {
...
@@ -265,10 +264,10 @@ class GestureArenaManager {
member
.
acceptGesture
(
pointer
);
member
.
acceptGesture
(
pointer
);
}
}
bool
_debugLogDiagnostic
(
int
pointer
,
String
message
,
[
_GestureArena
state
])
{
bool
_debugLogDiagnostic
(
int
pointer
,
String
message
,
[
_GestureArena
?
state
])
{
assert
(()
{
assert
(()
{
if
(
debugPrintGestureArenaDiagnostics
)
{
if
(
debugPrintGestureArenaDiagnostics
)
{
final
int
count
=
state
!=
null
?
state
.
members
.
length
:
null
;
final
int
?
count
=
state
!=
null
?
state
.
members
.
length
:
null
;
final
String
s
=
count
!=
1
?
's'
:
''
;
final
String
s
=
count
!=
1
?
's'
:
''
;
debugPrint
(
'Gesture arena
${pointer.toString().padRight(4)}
❙
$message${ count != null ? " with $count member$s." : ""}
'
);
debugPrint
(
'Gesture arena
${pointer.toString().padRight(4)}
❙
$message${ count != null ? " with $count member$s." : ""}
'
);
}
}
...
...
packages/flutter/lib/src/gestures/binding.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'dart:async'
;
import
'dart:collection'
;
import
'dart:collection'
;
...
@@ -75,8 +74,8 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
...
@@ -75,8 +74,8 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
}
}
/// The singleton instance of this object.
/// The singleton instance of this object.
static
GestureBinding
get
instance
=>
_instance
;
static
GestureBinding
?
get
instance
=>
_instance
;
static
GestureBinding
_instance
;
static
GestureBinding
?
_instance
;
final
Queue
<
PointerEvent
>
_pendingPointerEvents
=
Queue
<
PointerEvent
>();
final
Queue
<
PointerEvent
>
_pendingPointerEvents
=
Queue
<
PointerEvent
>();
...
@@ -123,7 +122,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
...
@@ -123,7 +122,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
void
_handlePointerEvent
(
PointerEvent
event
)
{
void
_handlePointerEvent
(
PointerEvent
event
)
{
assert
(!
locked
);
assert
(!
locked
);
HitTestResult
hitTestResult
;
HitTestResult
?
hitTestResult
;
if
(
event
is
PointerDownEvent
||
event
is
PointerSignalEvent
)
{
if
(
event
is
PointerDownEvent
||
event
is
PointerSignalEvent
)
{
assert
(!
_hitTests
.
containsKey
(
event
.
pointer
));
assert
(!
_hitTests
.
containsKey
(
event
.
pointer
));
hitTestResult
=
HitTestResult
();
hitTestResult
=
HitTestResult
();
...
@@ -172,7 +171,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
...
@@ -172,7 +171,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
/// might throw. The [hitTestResult] argument may only be null for
/// might throw. The [hitTestResult] argument may only be null for
/// [PointerHoverEvent], [PointerAddedEvent], or [PointerRemovedEvent] events.
/// [PointerHoverEvent], [PointerAddedEvent], or [PointerRemovedEvent] events.
@override
// from HitTestDispatcher
@override
// from HitTestDispatcher
void
dispatchEvent
(
PointerEvent
event
,
HitTestResult
hitTestResult
)
{
void
dispatchEvent
(
PointerEvent
event
,
HitTestResult
?
hitTestResult
)
{
assert
(!
locked
);
assert
(!
locked
);
// No hit test information implies that this is a hover or pointer
// No hit test information implies that this is a hover or pointer
// add/remove event.
// add/remove event.
...
@@ -243,12 +242,12 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
...
@@ -243,12 +242,12 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
/// that will subsequently be reported using [FlutterError.onError].
/// that will subsequently be reported using [FlutterError.onError].
const
FlutterErrorDetailsForPointerEventDispatcher
({
const
FlutterErrorDetailsForPointerEventDispatcher
({
dynamic
exception
,
dynamic
exception
,
StackTrace
stack
,
StackTrace
?
stack
,
String
library
,
String
?
library
,
DiagnosticsNode
context
,
DiagnosticsNode
?
context
,
this
.
event
,
this
.
event
,
this
.
hitTestEntry
,
this
.
hitTestEntry
,
InformationCollector
informationCollector
,
InformationCollector
?
informationCollector
,
bool
silent
=
false
,
bool
silent
=
false
,
})
:
super
(
})
:
super
(
exception:
exception
,
exception:
exception
,
...
@@ -260,7 +259,7 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
...
@@ -260,7 +259,7 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
);
);
/// The pointer event that was being routed when the exception was raised.
/// The pointer event that was being routed when the exception was raised.
final
PointerEvent
event
;
final
PointerEvent
?
event
;
/// The hit test result entry for the object whose handleEvent method threw
/// The hit test result entry for the object whose handleEvent method threw
/// the exception. May be null if no hit test entry is associated with the
/// the exception. May be null if no hit test entry is associated with the
...
@@ -268,5 +267,5 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
...
@@ -268,5 +267,5 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
///
///
/// The target object itself is given by the [HitTestEntry.target] property of
/// The target object itself is given by the [HitTestEntry.target] property of
/// the hitTestEntry object.
/// the hitTestEntry object.
final
HitTestEntry
hitTestEntry
;
final
HitTestEntry
?
hitTestEntry
;
}
}
packages/flutter/lib/src/gestures/constants.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
// Modeled after Android's ViewConfiguration:
// Modeled after Android's ViewConfiguration:
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java
...
...
packages/flutter/lib/src/gestures/converter.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:ui'
as
ui
show
PointerData
,
PointerChange
,
PointerSignalKind
;
import
'dart:ui'
as
ui
show
PointerData
,
PointerChange
,
PointerSignalKind
;
...
@@ -214,7 +213,7 @@ class PointerEventConverter {
...
@@ -214,7 +213,7 @@ class PointerEventConverter {
break
;
break
;
}
}
}
else
{
}
else
{
switch
(
datum
.
signalKind
)
{
switch
(
datum
.
signalKind
!
)
{
case
ui
.
PointerSignalKind
.
scroll
:
case
ui
.
PointerSignalKind
.
scroll
:
final
Offset
scrollDelta
=
final
Offset
scrollDelta
=
Offset
(
datum
.
scrollDeltaX
,
datum
.
scrollDeltaY
)
/
devicePixelRatio
;
Offset
(
datum
.
scrollDeltaX
,
datum
.
scrollDeltaY
)
/
devicePixelRatio
;
...
@@ -238,6 +237,5 @@ class PointerEventConverter {
...
@@ -238,6 +237,5 @@ class PointerEventConverter {
}
}
}
}
static
double
_toLogicalPixels
(
double
physicalPixels
,
double
devicePixelRatio
)
=>
static
double
_toLogicalPixels
(
double
physicalPixels
,
double
devicePixelRatio
)
=>
physicalPixels
/
devicePixelRatio
;
physicalPixels
==
null
?
null
:
physicalPixels
/
devicePixelRatio
;
}
}
packages/flutter/lib/src/gestures/debug.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
...
...
packages/flutter/lib/src/gestures/drag.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'drag_details.dart'
;
import
'drag_details.dart'
;
...
...
packages/flutter/lib/src/gestures/drag_details.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:ui'
show
Offset
;
import
'dart:ui'
show
Offset
;
...
@@ -24,7 +23,7 @@ class DragDownDetails {
...
@@ -24,7 +23,7 @@ class DragDownDetails {
/// The [globalPosition] argument must not be null.
/// The [globalPosition] argument must not be null.
DragDownDetails
({
DragDownDetails
({
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -71,7 +70,7 @@ class DragStartDetails {
...
@@ -71,7 +70,7 @@ class DragStartDetails {
DragStartDetails
({
DragStartDetails
({
this
.
sourceTimeStamp
,
this
.
sourceTimeStamp
,
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -79,7 +78,7 @@ class DragStartDetails {
...
@@ -79,7 +78,7 @@ class DragStartDetails {
/// event.
/// event.
///
///
/// Could be null if triggered from proxied events such as accessibility.
/// Could be null if triggered from proxied events such as accessibility.
final
Duration
sourceTimeStamp
;
final
Duration
?
sourceTimeStamp
;
/// The global position at which the pointer contacted the screen.
/// The global position at which the pointer contacted the screen.
///
///
...
@@ -134,8 +133,8 @@ class DragUpdateDetails {
...
@@ -134,8 +133,8 @@ class DragUpdateDetails {
this
.
sourceTimeStamp
,
this
.
sourceTimeStamp
,
this
.
delta
=
Offset
.
zero
,
this
.
delta
=
Offset
.
zero
,
this
.
primaryDelta
,
this
.
primaryDelta
,
@
required
this
.
globalPosition
,
required
this
.
globalPosition
,
Offset
localPosition
,
Offset
?
localPosition
,
})
:
assert
(
delta
!=
null
),
})
:
assert
(
delta
!=
null
),
assert
(
primaryDelta
==
null
assert
(
primaryDelta
==
null
||
(
primaryDelta
==
delta
.
dx
&&
delta
.
dy
==
0.0
)
||
(
primaryDelta
==
delta
.
dx
&&
delta
.
dy
==
0.0
)
...
@@ -146,7 +145,7 @@ class DragUpdateDetails {
...
@@ -146,7 +145,7 @@ class DragUpdateDetails {
/// event.
/// event.
///
///
/// Could be null if triggered from proxied events such as accessibility.
/// Could be null if triggered from proxied events such as accessibility.
final
Duration
sourceTimeStamp
;
final
Duration
?
sourceTimeStamp
;
/// The amount the pointer has moved in the coordinate space of the event
/// The amount the pointer has moved in the coordinate space of the event
/// receiver since the previous update.
/// receiver since the previous update.
...
@@ -169,7 +168,7 @@ class DragUpdateDetails {
...
@@ -169,7 +168,7 @@ class DragUpdateDetails {
/// two-dimensional drag (e.g., a pan), then this value is null.
/// two-dimensional drag (e.g., a pan), then this value is null.
///
///
/// Defaults to null if not specified in the constructor.
/// Defaults to null if not specified in the constructor.
final
double
primaryDelta
;
final
double
?
primaryDelta
;
/// The pointer's global position when it triggered this update.
/// The pointer's global position when it triggered this update.
///
///
...
@@ -233,7 +232,7 @@ class DragEndDetails {
...
@@ -233,7 +232,7 @@ class DragEndDetails {
/// two-dimensional drag (e.g., a pan), then this value is null.
/// two-dimensional drag (e.g., a pan), then this value is null.
///
///
/// Defaults to null if not specified in the constructor.
/// Defaults to null if not specified in the constructor.
final
double
primaryVelocity
;
final
double
?
primaryVelocity
;
@override
@override
String
toString
()
=>
'
${objectRuntimeType(this, 'DragEndDetails')}
(
$velocity
)'
;
String
toString
()
=>
'
${objectRuntimeType(this, 'DragEndDetails')}
(
$velocity
)'
;
...
...
packages/flutter/lib/src/gestures/eager.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'arena.dart'
;
import
'arena.dart'
;
import
'events.dart'
;
import
'events.dart'
;
...
@@ -17,7 +16,7 @@ class EagerGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -17,7 +16,7 @@ class EagerGestureRecognizer extends OneSequenceGestureRecognizer {
/// Create an eager gesture recognizer.
/// Create an eager gesture recognizer.
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
EagerGestureRecognizer
({
PointerDeviceKind
kind
})
:
super
(
kind:
kind
);
EagerGestureRecognizer
({
PointerDeviceKind
?
kind
})
:
super
(
kind:
kind
);
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
...
...
packages/flutter/lib/src/gestures/events.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:ui'
show
Offset
,
PointerDeviceKind
;
import
'dart:ui'
show
Offset
,
PointerDeviceKind
;
...
@@ -210,9 +209,9 @@ abstract class PointerEvent with Diagnosticable {
...
@@ -210,9 +209,9 @@ abstract class PointerEvent with Diagnosticable {
this
.
kind
=
PointerDeviceKind
.
touch
,
this
.
kind
=
PointerDeviceKind
.
touch
,
this
.
device
=
0
,
this
.
device
=
0
,
this
.
position
=
Offset
.
zero
,
this
.
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
this
.
delta
=
Offset
.
zero
,
this
.
delta
=
Offset
.
zero
,
Offset
localDelta
,
Offset
?
localDelta
,
this
.
buttons
=
0
,
this
.
buttons
=
0
,
this
.
down
=
false
,
this
.
down
=
false
,
this
.
obscured
=
false
,
this
.
obscured
=
false
,
...
@@ -459,7 +458,7 @@ abstract class PointerEvent with Diagnosticable {
...
@@ -459,7 +458,7 @@ abstract class PointerEvent with Diagnosticable {
///
///
/// * [transformed], which transforms this event into a different coordinate
/// * [transformed], which transforms this event into a different coordinate
/// space.
/// space.
final
Matrix4
transform
;
final
Matrix4
?
transform
;
/// The original un-transformed [PointerEvent] before any [transform]s were
/// The original un-transformed [PointerEvent] before any [transform]s were
/// applied.
/// applied.
...
@@ -470,7 +469,7 @@ abstract class PointerEvent with Diagnosticable {
...
@@ -470,7 +469,7 @@ abstract class PointerEvent with Diagnosticable {
/// event, they all receive the event transformed to their local coordinate
/// event, they all receive the event transformed to their local coordinate
/// space. The [original] property can be used to determine if all those
/// space. The [original] property can be used to determine if all those
/// transformed events actually originated from the same pointer interaction.
/// transformed events actually originated from the same pointer interaction.
final
PointerEvent
original
;
final
PointerEvent
?
original
;
/// Transforms the event from the global coordinate space into the coordinate
/// Transforms the event from the global coordinate space into the coordinate
/// space of an event receiver.
/// space of an event receiver.
...
@@ -484,7 +483,7 @@ abstract class PointerEvent with Diagnosticable {
...
@@ -484,7 +483,7 @@ abstract class PointerEvent with Diagnosticable {
/// Transforms are not commutative. If this method is called on a
/// Transforms are not commutative. If this method is called on a
/// [PointerEvent] that has a non-null [transform] value, that value will be
/// [PointerEvent] that has a non-null [transform] value, that value will be
/// overridden by the provided `transform`.
/// overridden by the provided `transform`.
PointerEvent
transformed
(
Matrix4
transform
);
PointerEvent
transformed
(
Matrix4
?
transform
);
@override
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
...
@@ -528,7 +527,7 @@ abstract class PointerEvent with Diagnosticable {
...
@@ -528,7 +527,7 @@ abstract class PointerEvent with Diagnosticable {
///
///
/// The z-value of `position` is assumed to be 0.0. If `transform` is null,
/// The z-value of `position` is assumed to be 0.0. If `transform` is null,
/// `position` is returned as-is.
/// `position` is returned as-is.
static
Offset
transformPosition
(
Matrix4
transform
,
Offset
position
)
{
static
Offset
transformPosition
(
Matrix4
?
transform
,
Offset
position
)
{
if
(
transform
==
null
)
{
if
(
transform
==
null
)
{
return
position
;
return
position
;
}
}
...
@@ -545,10 +544,10 @@ abstract class PointerEvent with Diagnosticable {
...
@@ -545,10 +544,10 @@ abstract class PointerEvent with Diagnosticable {
///
///
/// If `transform` is null, `untransformedDelta` is returned.
/// If `transform` is null, `untransformedDelta` is returned.
static
Offset
transformDeltaViaPositions
({
static
Offset
transformDeltaViaPositions
({
@
required
Offset
untransformedEndPosition
,
required
Offset
untransformedEndPosition
,
Offset
transformedEndPosition
,
Offset
?
transformedEndPosition
,
@
required
Offset
untransformedDelta
,
required
Offset
untransformedDelta
,
@required
Matrix4
transform
,
required
Matrix4
?
transform
,
})
{
})
{
if
(
transform
==
null
)
{
if
(
transform
==
null
)
{
return
untransformedDelta
;
return
untransformedDelta
;
...
@@ -592,7 +591,7 @@ class PointerAddedEvent extends PointerEvent {
...
@@ -592,7 +591,7 @@ class PointerAddedEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressureMin
=
1.0
,
double
pressureMin
=
1.0
,
double
pressureMax
=
1.0
,
double
pressureMax
=
1.0
,
...
@@ -602,8 +601,8 @@ class PointerAddedEvent extends PointerEvent {
...
@@ -602,8 +601,8 @@ class PointerAddedEvent extends PointerEvent {
double
radiusMax
=
0.0
,
double
radiusMax
=
0.0
,
double
orientation
=
0.0
,
double
orientation
=
0.0
,
double
tilt
=
0.0
,
double
tilt
=
0.0
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerAddedEvent
original
,
PointerAddedEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -627,7 +626,7 @@ class PointerAddedEvent extends PointerEvent {
...
@@ -627,7 +626,7 @@ class PointerAddedEvent extends PointerEvent {
);
);
@override
@override
PointerAddedEvent
transformed
(
Matrix4
transform
)
{
PointerAddedEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -647,7 +646,7 @@ class PointerAddedEvent extends PointerEvent {
...
@@ -647,7 +646,7 @@ class PointerAddedEvent extends PointerEvent {
orientation:
orientation
,
orientation:
orientation
,
tilt:
tilt
,
tilt:
tilt
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerAddedEvent
??
this
,
original:
original
as
PointerAddedEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -666,15 +665,15 @@ class PointerRemovedEvent extends PointerEvent {
...
@@ -666,15 +665,15 @@ class PointerRemovedEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressureMin
=
1.0
,
double
pressureMin
=
1.0
,
double
pressureMax
=
1.0
,
double
pressureMax
=
1.0
,
double
distanceMax
=
0.0
,
double
distanceMax
=
0.0
,
double
radiusMin
=
0.0
,
double
radiusMin
=
0.0
,
double
radiusMax
=
0.0
,
double
radiusMax
=
0.0
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerRemovedEvent
original
,
PointerRemovedEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -695,7 +694,7 @@ class PointerRemovedEvent extends PointerEvent {
...
@@ -695,7 +694,7 @@ class PointerRemovedEvent extends PointerEvent {
);
);
@override
@override
PointerRemovedEvent
transformed
(
Matrix4
transform
)
{
PointerRemovedEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -712,7 +711,7 @@ class PointerRemovedEvent extends PointerEvent {
...
@@ -712,7 +711,7 @@ class PointerRemovedEvent extends PointerEvent {
radiusMin:
radiusMin
,
radiusMin:
radiusMin
,
radiusMax:
radiusMax
,
radiusMax:
radiusMax
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerRemovedEvent
??
this
,
original:
original
as
PointerRemovedEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -739,9 +738,9 @@ class PointerHoverEvent extends PointerEvent {
...
@@ -739,9 +738,9 @@ class PointerHoverEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
Offset
delta
=
Offset
.
zero
,
Offset
delta
=
Offset
.
zero
,
Offset
localDelta
,
Offset
?
localDelta
,
int
buttons
=
0
,
int
buttons
=
0
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressureMin
=
1.0
,
double
pressureMin
=
1.0
,
...
@@ -756,8 +755,8 @@ class PointerHoverEvent extends PointerEvent {
...
@@ -756,8 +755,8 @@ class PointerHoverEvent extends PointerEvent {
double
orientation
=
0.0
,
double
orientation
=
0.0
,
double
tilt
=
0.0
,
double
tilt
=
0.0
,
bool
synthesized
=
false
,
bool
synthesized
=
false
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerHoverEvent
original
,
PointerHoverEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -789,7 +788,7 @@ class PointerHoverEvent extends PointerEvent {
...
@@ -789,7 +788,7 @@ class PointerHoverEvent extends PointerEvent {
);
);
@override
@override
PointerHoverEvent
transformed
(
Matrix4
transform
)
{
PointerHoverEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -822,7 +821,7 @@ class PointerHoverEvent extends PointerEvent {
...
@@ -822,7 +821,7 @@ class PointerHoverEvent extends PointerEvent {
tilt:
tilt
,
tilt:
tilt
,
synthesized:
synthesized
,
synthesized:
synthesized
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerHoverEvent
??
this
,
original:
original
as
PointerHoverEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -849,9 +848,9 @@ class PointerEnterEvent extends PointerEvent {
...
@@ -849,9 +848,9 @@ class PointerEnterEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
Offset
delta
=
Offset
.
zero
,
Offset
delta
=
Offset
.
zero
,
Offset
localDelta
,
Offset
?
localDelta
,
int
buttons
=
0
,
int
buttons
=
0
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressureMin
=
1.0
,
double
pressureMin
=
1.0
,
...
@@ -867,8 +866,8 @@ class PointerEnterEvent extends PointerEvent {
...
@@ -867,8 +866,8 @@ class PointerEnterEvent extends PointerEvent {
double
tilt
=
0.0
,
double
tilt
=
0.0
,
bool
down
=
false
,
bool
down
=
false
,
bool
synthesized
=
false
,
bool
synthesized
=
false
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerEnterEvent
original
,
PointerEnterEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -912,34 +911,34 @@ class PointerEnterEvent extends PointerEvent {
...
@@ -912,34 +911,34 @@ class PointerEnterEvent extends PointerEvent {
///
///
/// This is used by the [MouseTracker] to synthesize enter events.
/// This is used by the [MouseTracker] to synthesize enter events.
PointerEnterEvent
.
fromMouseEvent
(
PointerEvent
event
)
:
this
(
PointerEnterEvent
.
fromMouseEvent
(
PointerEvent
event
)
:
this
(
timeStamp:
event
?
.
timeStamp
,
timeStamp:
event
.
timeStamp
,
kind:
event
?
.
kind
,
kind:
event
.
kind
,
device:
event
?
.
device
,
device:
event
.
device
,
position:
event
?
.
position
,
position:
event
.
position
,
localPosition:
event
?
.
localPosition
,
localPosition:
event
.
localPosition
,
delta:
event
?
.
delta
,
delta:
event
.
delta
,
localDelta:
event
?
.
localDelta
,
localDelta:
event
.
localDelta
,
buttons:
event
?
.
buttons
,
buttons:
event
.
buttons
,
obscured:
event
?
.
obscured
,
obscured:
event
.
obscured
,
pressureMin:
event
?
.
pressureMin
,
pressureMin:
event
.
pressureMin
,
pressureMax:
event
?
.
pressureMax
,
pressureMax:
event
.
pressureMax
,
distance:
event
?
.
distance
,
distance:
event
.
distance
,
distanceMax:
event
?
.
distanceMax
,
distanceMax:
event
.
distanceMax
,
size:
event
?
.
size
,
size:
event
.
size
,
radiusMajor:
event
?
.
radiusMajor
,
radiusMajor:
event
.
radiusMajor
,
radiusMinor:
event
?
.
radiusMinor
,
radiusMinor:
event
.
radiusMinor
,
radiusMin:
event
?
.
radiusMin
,
radiusMin:
event
.
radiusMin
,
radiusMax:
event
?
.
radiusMax
,
radiusMax:
event
.
radiusMax
,
orientation:
event
?
.
orientation
,
orientation:
event
.
orientation
,
tilt:
event
?
.
tilt
,
tilt:
event
.
tilt
,
down:
event
?
.
down
,
down:
event
.
down
,
synthesized:
event
?
.
synthesized
,
synthesized:
event
.
synthesized
,
transform:
event
?
.
transform
,
transform:
event
.
transform
,
original:
null
,
original:
null
,
);
);
@override
@override
PointerEnterEvent
transformed
(
Matrix4
transform
)
{
PointerEnterEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -973,7 +972,7 @@ class PointerEnterEvent extends PointerEvent {
...
@@ -973,7 +972,7 @@ class PointerEnterEvent extends PointerEvent {
down:
down
,
down:
down
,
synthesized:
synthesized
,
synthesized:
synthesized
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerEnterEvent
??
this
,
original:
original
as
PointerEnterEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -1000,9 +999,9 @@ class PointerExitEvent extends PointerEvent {
...
@@ -1000,9 +999,9 @@ class PointerExitEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
Offset
delta
=
Offset
.
zero
,
Offset
delta
=
Offset
.
zero
,
Offset
localDelta
,
Offset
?
localDelta
,
int
buttons
=
0
,
int
buttons
=
0
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressureMin
=
1.0
,
double
pressureMin
=
1.0
,
...
@@ -1018,8 +1017,8 @@ class PointerExitEvent extends PointerEvent {
...
@@ -1018,8 +1017,8 @@ class PointerExitEvent extends PointerEvent {
double
tilt
=
0.0
,
double
tilt
=
0.0
,
bool
down
=
false
,
bool
down
=
false
,
bool
synthesized
=
false
,
bool
synthesized
=
false
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerExitEvent
original
,
PointerExitEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -1063,34 +1062,34 @@ class PointerExitEvent extends PointerEvent {
...
@@ -1063,34 +1062,34 @@ class PointerExitEvent extends PointerEvent {
///
///
/// This is used by the [MouseTracker] to synthesize exit events.
/// This is used by the [MouseTracker] to synthesize exit events.
PointerExitEvent
.
fromMouseEvent
(
PointerEvent
event
)
:
this
(
PointerExitEvent
.
fromMouseEvent
(
PointerEvent
event
)
:
this
(
timeStamp:
event
?
.
timeStamp
,
timeStamp:
event
.
timeStamp
,
kind:
event
?
.
kind
,
kind:
event
.
kind
,
device:
event
?
.
device
,
device:
event
.
device
,
position:
event
?
.
position
,
position:
event
.
position
,
localPosition:
event
?
.
localPosition
,
localPosition:
event
.
localPosition
,
delta:
event
?
.
delta
,
delta:
event
.
delta
,
localDelta:
event
?
.
localDelta
,
localDelta:
event
.
localDelta
,
buttons:
event
?
.
buttons
,
buttons:
event
.
buttons
,
obscured:
event
?
.
obscured
,
obscured:
event
.
obscured
,
pressureMin:
event
?
.
pressureMin
,
pressureMin:
event
.
pressureMin
,
pressureMax:
event
?
.
pressureMax
,
pressureMax:
event
.
pressureMax
,
distance:
event
?
.
distance
,
distance:
event
.
distance
,
distanceMax:
event
?
.
distanceMax
,
distanceMax:
event
.
distanceMax
,
size:
event
?
.
size
,
size:
event
.
size
,
radiusMajor:
event
?
.
radiusMajor
,
radiusMajor:
event
.
radiusMajor
,
radiusMinor:
event
?
.
radiusMinor
,
radiusMinor:
event
.
radiusMinor
,
radiusMin:
event
?
.
radiusMin
,
radiusMin:
event
.
radiusMin
,
radiusMax:
event
?
.
radiusMax
,
radiusMax:
event
.
radiusMax
,
orientation:
event
?
.
orientation
,
orientation:
event
.
orientation
,
tilt:
event
?
.
tilt
,
tilt:
event
.
tilt
,
down:
event
?
.
down
,
down:
event
.
down
,
synthesized:
event
?
.
synthesized
,
synthesized:
event
.
synthesized
,
transform:
event
?
.
transform
,
transform:
event
.
transform
,
original:
null
,
original:
null
,
);
);
@override
@override
PointerExitEvent
transformed
(
Matrix4
transform
)
{
PointerExitEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -1124,7 +1123,7 @@ class PointerExitEvent extends PointerEvent {
...
@@ -1124,7 +1123,7 @@ class PointerExitEvent extends PointerEvent {
down:
down
,
down:
down
,
synthesized:
synthesized
,
synthesized:
synthesized
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerExitEvent
??
this
,
original:
original
as
PointerExitEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -1146,7 +1145,7 @@ class PointerDownEvent extends PointerEvent {
...
@@ -1146,7 +1145,7 @@ class PointerDownEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
int
buttons
=
kPrimaryButton
,
int
buttons
=
kPrimaryButton
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressure
=
1.0
,
double
pressure
=
1.0
,
...
@@ -1160,8 +1159,8 @@ class PointerDownEvent extends PointerEvent {
...
@@ -1160,8 +1159,8 @@ class PointerDownEvent extends PointerEvent {
double
radiusMax
=
0.0
,
double
radiusMax
=
0.0
,
double
orientation
=
0.0
,
double
orientation
=
0.0
,
double
tilt
=
0.0
,
double
tilt
=
0.0
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerDownEvent
original
,
PointerDownEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -1191,7 +1190,7 @@ class PointerDownEvent extends PointerEvent {
...
@@ -1191,7 +1190,7 @@ class PointerDownEvent extends PointerEvent {
);
);
@override
@override
PointerDownEvent
transformed
(
Matrix4
transform
)
{
PointerDownEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -1216,7 +1215,7 @@ class PointerDownEvent extends PointerEvent {
...
@@ -1216,7 +1215,7 @@ class PointerDownEvent extends PointerEvent {
orientation:
orientation
,
orientation:
orientation
,
tilt:
tilt
,
tilt:
tilt
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerDownEvent
??
this
,
original:
original
as
PointerDownEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -1241,9 +1240,9 @@ class PointerMoveEvent extends PointerEvent {
...
@@ -1241,9 +1240,9 @@ class PointerMoveEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
Offset
delta
=
Offset
.
zero
,
Offset
delta
=
Offset
.
zero
,
Offset
localDelta
,
Offset
?
localDelta
,
int
buttons
=
kPrimaryButton
,
int
buttons
=
kPrimaryButton
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressure
=
1.0
,
double
pressure
=
1.0
,
...
@@ -1259,8 +1258,8 @@ class PointerMoveEvent extends PointerEvent {
...
@@ -1259,8 +1258,8 @@ class PointerMoveEvent extends PointerEvent {
double
tilt
=
0.0
,
double
tilt
=
0.0
,
int
platformData
=
0
,
int
platformData
=
0
,
bool
synthesized
=
false
,
bool
synthesized
=
false
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerMoveEvent
original
,
PointerMoveEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -1294,7 +1293,7 @@ class PointerMoveEvent extends PointerEvent {
...
@@ -1294,7 +1293,7 @@ class PointerMoveEvent extends PointerEvent {
);
);
@override
@override
PointerMoveEvent
transformed
(
Matrix4
transform
)
{
PointerMoveEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -1330,7 +1329,7 @@ class PointerMoveEvent extends PointerEvent {
...
@@ -1330,7 +1329,7 @@ class PointerMoveEvent extends PointerEvent {
platformData:
platformData
,
platformData:
platformData
,
synthesized:
synthesized
,
synthesized:
synthesized
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerMoveEvent
??
this
,
original:
original
as
PointerMoveEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -1352,7 +1351,7 @@ class PointerUpEvent extends PointerEvent {
...
@@ -1352,7 +1351,7 @@ class PointerUpEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
int
buttons
=
0
,
int
buttons
=
0
,
bool
obscured
=
false
,
bool
obscured
=
false
,
// Allow pressure customization here because PointerUpEvent can contain
// Allow pressure customization here because PointerUpEvent can contain
...
@@ -1369,8 +1368,8 @@ class PointerUpEvent extends PointerEvent {
...
@@ -1369,8 +1368,8 @@ class PointerUpEvent extends PointerEvent {
double
radiusMax
=
0.0
,
double
radiusMax
=
0.0
,
double
orientation
=
0.0
,
double
orientation
=
0.0
,
double
tilt
=
0.0
,
double
tilt
=
0.0
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerUpEvent
original
,
PointerUpEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -1400,7 +1399,7 @@ class PointerUpEvent extends PointerEvent {
...
@@ -1400,7 +1399,7 @@ class PointerUpEvent extends PointerEvent {
);
);
@override
@override
PointerUpEvent
transformed
(
Matrix4
transform
)
{
PointerUpEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -1426,7 +1425,7 @@ class PointerUpEvent extends PointerEvent {
...
@@ -1426,7 +1425,7 @@ class PointerUpEvent extends PointerEvent {
orientation:
orientation
,
orientation:
orientation
,
tilt:
tilt
,
tilt:
tilt
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerUpEvent
??
this
,
original:
original
as
PointerUpEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -1451,9 +1450,9 @@ abstract class PointerSignalEvent extends PointerEvent {
...
@@ -1451,9 +1450,9 @@ abstract class PointerSignalEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
mouse
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
mouse
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerSignalEvent
original
,
PointerSignalEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -1486,10 +1485,10 @@ class PointerScrollEvent extends PointerSignalEvent {
...
@@ -1486,10 +1485,10 @@ class PointerScrollEvent extends PointerSignalEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
mouse
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
mouse
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
this
.
scrollDelta
=
Offset
.
zero
,
this
.
scrollDelta
=
Offset
.
zero
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerScrollEvent
original
,
PointerScrollEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
assert
(
timeStamp
!=
null
),
})
:
assert
(
timeStamp
!=
null
),
assert
(
kind
!=
null
),
assert
(
kind
!=
null
),
...
@@ -1511,7 +1510,7 @@ class PointerScrollEvent extends PointerSignalEvent {
...
@@ -1511,7 +1510,7 @@ class PointerScrollEvent extends PointerSignalEvent {
final
Offset
scrollDelta
;
final
Offset
scrollDelta
;
@override
@override
PointerScrollEvent
transformed
(
Matrix4
transform
)
{
PointerScrollEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -1523,7 +1522,7 @@ class PointerScrollEvent extends PointerSignalEvent {
...
@@ -1523,7 +1522,7 @@ class PointerScrollEvent extends PointerSignalEvent {
localPosition:
PointerEvent
.
transformPosition
(
transform
,
position
),
localPosition:
PointerEvent
.
transformPosition
(
transform
,
position
),
scrollDelta:
scrollDelta
,
scrollDelta:
scrollDelta
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerScrollEvent
??
this
,
original:
original
as
PointerScrollEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
@@ -1551,7 +1550,7 @@ class PointerCancelEvent extends PointerEvent {
...
@@ -1551,7 +1550,7 @@ class PointerCancelEvent extends PointerEvent {
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
,
int
device
=
0
,
int
device
=
0
,
Offset
position
=
Offset
.
zero
,
Offset
position
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
int
buttons
=
0
,
int
buttons
=
0
,
bool
obscured
=
false
,
bool
obscured
=
false
,
double
pressureMin
=
1.0
,
double
pressureMin
=
1.0
,
...
@@ -1565,8 +1564,8 @@ class PointerCancelEvent extends PointerEvent {
...
@@ -1565,8 +1564,8 @@ class PointerCancelEvent extends PointerEvent {
double
radiusMax
=
0.0
,
double
radiusMax
=
0.0
,
double
orientation
=
0.0
,
double
orientation
=
0.0
,
double
tilt
=
0.0
,
double
tilt
=
0.0
,
Matrix4
transform
,
Matrix4
?
transform
,
PointerCancelEvent
original
,
PointerCancelEvent
?
original
,
int
embedderId
=
0
,
int
embedderId
=
0
,
})
:
super
(
})
:
super
(
timeStamp:
timeStamp
,
timeStamp:
timeStamp
,
...
@@ -1596,7 +1595,7 @@ class PointerCancelEvent extends PointerEvent {
...
@@ -1596,7 +1595,7 @@ class PointerCancelEvent extends PointerEvent {
);
);
@override
@override
PointerCancelEvent
transformed
(
Matrix4
transform
)
{
PointerCancelEvent
transformed
(
Matrix4
?
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
if
(
transform
==
null
||
transform
==
this
.
transform
)
{
return
this
;
return
this
;
}
}
...
@@ -1621,7 +1620,7 @@ class PointerCancelEvent extends PointerEvent {
...
@@ -1621,7 +1620,7 @@ class PointerCancelEvent extends PointerEvent {
orientation:
orientation
,
orientation:
orientation
,
tilt:
tilt
,
tilt:
tilt
,
transform:
transform
,
transform:
transform
,
original:
original
as
PointerCancelEvent
??
this
,
original:
original
as
PointerCancelEvent
?
??
this
,
embedderId:
embedderId
,
embedderId:
embedderId
,
);
);
}
}
...
...
packages/flutter/lib/src/gestures/force_press.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:ui'
show
Offset
;
import
'dart:ui'
show
Offset
;
...
@@ -51,9 +50,9 @@ class ForcePressDetails {
...
@@ -51,9 +50,9 @@ class ForcePressDetails {
///
///
/// The [globalPosition] argument must not be null.
/// The [globalPosition] argument must not be null.
ForcePressDetails
({
ForcePressDetails
({
@
required
this
.
globalPosition
,
required
this
.
globalPosition
,
Offset
localPosition
,
Offset
?
localPosition
,
@
required
this
.
pressure
,
required
this
.
pressure
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
assert
(
pressure
!=
null
),
assert
(
pressure
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -128,8 +127,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -128,8 +127,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
this
.
startPressure
=
0.4
,
this
.
startPressure
=
0.4
,
this
.
peakPressure
=
0.85
,
this
.
peakPressure
=
0.85
,
this
.
interpolation
=
_inverseLerp
,
this
.
interpolation
=
_inverseLerp
,
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
assert
(
startPressure
!=
null
),
})
:
assert
(
startPressure
!=
null
),
assert
(
peakPressure
!=
null
),
assert
(
peakPressure
!=
null
),
assert
(
interpolation
!=
null
),
assert
(
interpolation
!=
null
),
...
@@ -143,7 +142,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -143,7 +142,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// The position of the pointer is provided in the callback's `details`
/// The position of the pointer is provided in the callback's `details`
/// argument, which is a [ForcePressDetails] object.
/// argument, which is a [ForcePressDetails] object.
GestureForcePressStartCallback
onStart
;
GestureForcePressStartCallback
?
onStart
;
/// A pointer is in contact with the screen and is either moving on the plane
/// A pointer is in contact with the screen and is either moving on the plane
/// of the screen, pressing the screen with varying forces or both
/// of the screen, pressing the screen with varying forces or both
...
@@ -154,7 +153,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -154,7 +153,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// matter what the pressure is during this time period. The position and
/// matter what the pressure is during this time period. The position and
/// pressure of the pointer is provided in the callback's `details` argument,
/// pressure of the pointer is provided in the callback's `details` argument,
/// which is a [ForcePressDetails] object.
/// which is a [ForcePressDetails] object.
GestureForcePressUpdateCallback
onUpdate
;
GestureForcePressUpdateCallback
?
onUpdate
;
/// A pointer is in contact with the screen and has just pressed with a force
/// A pointer is in contact with the screen and has just pressed with a force
/// exceeding the [peakPressure]. This is an arbitrary second level action
/// exceeding the [peakPressure]. This is an arbitrary second level action
...
@@ -163,13 +162,13 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -163,13 +162,13 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// The position of the pointer is provided in the callback's `details`
/// The position of the pointer is provided in the callback's `details`
/// argument, which is a [ForcePressDetails] object.
/// argument, which is a [ForcePressDetails] object.
GestureForcePressPeakCallback
onPeak
;
GestureForcePressPeakCallback
?
onPeak
;
/// A pointer is no longer in contact with the screen.
/// A pointer is no longer in contact with the screen.
///
///
/// The position of the pointer is provided in the callback's `details`
/// The position of the pointer is provided in the callback's `details`
/// argument, which is a [ForcePressDetails] object.
/// argument, which is a [ForcePressDetails] object.
GestureForcePressEndCallback
onEnd
;
GestureForcePressEndCallback
?
onEnd
;
/// The pressure of the press required to initiate a force press.
/// The pressure of the press required to initiate a force press.
///
///
...
@@ -209,8 +208,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -209,8 +208,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// ```
/// ```
final
GestureForceInterpolation
interpolation
;
final
GestureForceInterpolation
interpolation
;
OffsetPair
_lastPosition
;
late
OffsetPair
_lastPosition
;
double
_lastPressure
;
late
double
_lastPressure
;
_ForceState
_state
=
_ForceState
.
ready
;
_ForceState
_state
=
_ForceState
.
ready
;
@override
@override
...
@@ -264,7 +263,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -264,7 +263,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
pressure
>
startPressure
&&
_state
==
_ForceState
.
accepted
)
{
if
(
pressure
>
startPressure
&&
_state
==
_ForceState
.
accepted
)
{
_state
=
_ForceState
.
started
;
_state
=
_ForceState
.
started
;
if
(
onStart
!=
null
)
{
if
(
onStart
!=
null
)
{
invokeCallback
<
void
>(
'onStart'
,
()
=>
onStart
(
ForcePressDetails
(
invokeCallback
<
void
>(
'onStart'
,
()
=>
onStart
!
(
ForcePressDetails
(
pressure:
pressure
,
pressure:
pressure
,
globalPosition:
_lastPosition
.
global
,
globalPosition:
_lastPosition
.
global
,
localPosition:
_lastPosition
.
local
,
localPosition:
_lastPosition
.
local
,
...
@@ -275,7 +274,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -275,7 +274,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
(
_state
==
_ForceState
.
started
))
{
(
_state
==
_ForceState
.
started
))
{
_state
=
_ForceState
.
peaked
;
_state
=
_ForceState
.
peaked
;
if
(
onPeak
!=
null
)
{
if
(
onPeak
!=
null
)
{
invokeCallback
<
void
>(
'onPeak'
,
()
=>
onPeak
(
ForcePressDetails
(
invokeCallback
<
void
>(
'onPeak'
,
()
=>
onPeak
!
(
ForcePressDetails
(
pressure:
pressure
,
pressure:
pressure
,
globalPosition:
event
.
position
,
globalPosition:
event
.
position
,
localPosition:
event
.
localPosition
,
localPosition:
event
.
localPosition
,
...
@@ -285,7 +284,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -285,7 +284,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
onUpdate
!=
null
&&
!
pressure
.
isNaN
&&
if
(
onUpdate
!=
null
&&
!
pressure
.
isNaN
&&
(
_state
==
_ForceState
.
started
||
_state
==
_ForceState
.
peaked
))
{
(
_state
==
_ForceState
.
started
||
_state
==
_ForceState
.
peaked
))
{
if
(
onUpdate
!=
null
)
{
if
(
onUpdate
!=
null
)
{
invokeCallback
<
void
>(
'onUpdate'
,
()
=>
onUpdate
(
ForcePressDetails
(
invokeCallback
<
void
>(
'onUpdate'
,
()
=>
onUpdate
!
(
ForcePressDetails
(
pressure:
pressure
,
pressure:
pressure
,
globalPosition:
event
.
position
,
globalPosition:
event
.
position
,
localPosition:
event
.
localPosition
,
localPosition:
event
.
localPosition
,
...
@@ -302,7 +301,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -302,7 +301,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
_state
=
_ForceState
.
accepted
;
_state
=
_ForceState
.
accepted
;
if
(
onStart
!=
null
&&
_state
==
_ForceState
.
started
)
{
if
(
onStart
!=
null
&&
_state
==
_ForceState
.
started
)
{
invokeCallback
<
void
>(
'onStart'
,
()
=>
onStart
(
ForcePressDetails
(
invokeCallback
<
void
>(
'onStart'
,
()
=>
onStart
!
(
ForcePressDetails
(
pressure:
_lastPressure
,
pressure:
_lastPressure
,
globalPosition:
_lastPosition
.
global
,
globalPosition:
_lastPosition
.
global
,
localPosition:
_lastPosition
.
local
,
localPosition:
_lastPosition
.
local
,
...
@@ -319,7 +318,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -319,7 +318,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
}
}
if
(
wasAccepted
&&
onEnd
!=
null
)
{
if
(
wasAccepted
&&
onEnd
!=
null
)
{
if
(
onEnd
!=
null
)
{
if
(
onEnd
!=
null
)
{
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
(
ForcePressDetails
(
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
!
(
ForcePressDetails
(
pressure:
0.0
,
pressure:
0.0
,
globalPosition:
_lastPosition
.
global
,
globalPosition:
_lastPosition
.
global
,
localPosition:
_lastPosition
.
local
,
localPosition:
_lastPosition
.
local
,
...
...
packages/flutter/lib/src/gestures/hit_test.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
...
@@ -13,8 +12,7 @@ import 'events.dart';
...
@@ -13,8 +12,7 @@ import 'events.dart';
abstract
class
HitTestable
{
abstract
class
HitTestable
{
// This class is intended to be used as an interface, and should not be
// This class is intended to be used as an interface, and should not be
// extended directly; this constructor prevents instantiation and extension.
// extended directly; this constructor prevents instantiation and extension.
// ignore: unused_element
HitTestable
.
_
();
factory
HitTestable
.
_
()
=>
null
;
/// Check whether the given position hits this object.
/// Check whether the given position hits this object.
///
///
...
@@ -27,8 +25,7 @@ abstract class HitTestable {
...
@@ -27,8 +25,7 @@ abstract class HitTestable {
abstract
class
HitTestDispatcher
{
abstract
class
HitTestDispatcher
{
// This class is intended to be used as an interface, and should not be
// This class is intended to be used as an interface, and should not be
// extended directly; this constructor prevents instantiation and extension.
// extended directly; this constructor prevents instantiation and extension.
// ignore: unused_element
HitTestDispatcher
.
_
();
factory
HitTestDispatcher
.
_
()
=>
null
;
/// Override this method to dispatch events.
/// Override this method to dispatch events.
void
dispatchEvent
(
PointerEvent
event
,
HitTestResult
result
);
void
dispatchEvent
(
PointerEvent
event
,
HitTestResult
result
);
...
@@ -38,8 +35,7 @@ abstract class HitTestDispatcher {
...
@@ -38,8 +35,7 @@ abstract class HitTestDispatcher {
abstract
class
HitTestTarget
{
abstract
class
HitTestTarget
{
// This class is intended to be used as an interface, and should not be
// This class is intended to be used as an interface, and should not be
// extended directly; this constructor prevents instantiation and extension.
// extended directly; this constructor prevents instantiation and extension.
// ignore: unused_element
HitTestTarget
.
_
();
factory
HitTestTarget
.
_
()
=>
null
;
/// Override this method to receive events.
/// Override this method to receive events.
void
handleEvent
(
PointerEvent
event
,
HitTestEntry
entry
);
void
handleEvent
(
PointerEvent
event
,
HitTestEntry
entry
);
...
@@ -67,8 +63,8 @@ class HitTestEntry {
...
@@ -67,8 +63,8 @@ class HitTestEntry {
///
///
/// * [BoxHitTestResult.addWithPaintTransform], which is used during hit testing
/// * [BoxHitTestResult.addWithPaintTransform], which is used during hit testing
/// to build up this transform.
/// to build up this transform.
Matrix4
get
transform
=>
_transform
;
Matrix4
?
get
transform
=>
_transform
;
Matrix4
_transform
;
Matrix4
?
_transform
;
}
}
// A type of data that can be applied to a matrix by left-multiplication.
// A type of data that can be applied to a matrix by left-multiplication.
...
...
packages/flutter/lib/src/gestures/long_press.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'arena.dart'
;
import
'arena.dart'
;
import
'constants.dart'
;
import
'constants.dart'
;
...
@@ -56,7 +55,7 @@ class LongPressStartDetails {
...
@@ -56,7 +55,7 @@ class LongPressStartDetails {
/// The [globalPosition] argument must not be null.
/// The [globalPosition] argument must not be null.
const
LongPressStartDetails
({
const
LongPressStartDetails
({
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -80,9 +79,9 @@ class LongPressMoveUpdateDetails {
...
@@ -80,9 +79,9 @@ class LongPressMoveUpdateDetails {
/// The [globalPosition] and [offsetFromOrigin] arguments must not be null.
/// The [globalPosition] and [offsetFromOrigin] arguments must not be null.
const
LongPressMoveUpdateDetails
({
const
LongPressMoveUpdateDetails
({
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
this
.
offsetFromOrigin
=
Offset
.
zero
,
this
.
offsetFromOrigin
=
Offset
.
zero
,
Offset
localOffsetFromOrigin
,
Offset
?
localOffsetFromOrigin
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
assert
(
offsetFromOrigin
!=
null
),
assert
(
offsetFromOrigin
!=
null
),
localPosition
=
localPosition
??
globalPosition
,
localPosition
=
localPosition
??
globalPosition
,
...
@@ -118,7 +117,7 @@ class LongPressEndDetails {
...
@@ -118,7 +117,7 @@ class LongPressEndDetails {
/// The [globalPosition] argument must not be null.
/// The [globalPosition] argument must not be null.
const
LongPressEndDetails
({
const
LongPressEndDetails
({
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
this
.
velocity
=
Velocity
.
zero
,
this
.
velocity
=
Velocity
.
zero
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -162,10 +161,10 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -162,10 +161,10 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// The [duration] argument can be used to overwrite the default duration
/// The [duration] argument can be used to overwrite the default duration
/// after which the long press will be recognized.
/// after which the long press will be recognized.
LongPressGestureRecognizer
({
LongPressGestureRecognizer
({
Duration
duration
,
Duration
?
duration
,
double
postAcceptSlopTolerance
,
double
?
postAcceptSlopTolerance
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
Object
debugOwner
,
Object
?
debugOwner
,
})
:
super
(
})
:
super
(
deadline:
duration
??
kLongPressTimeout
,
deadline:
duration
??
kLongPressTimeout
,
postAcceptSlopTolerance:
postAcceptSlopTolerance
,
postAcceptSlopTolerance:
postAcceptSlopTolerance
,
...
@@ -174,10 +173,10 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -174,10 +173,10 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
);
);
bool
_longPressAccepted
=
false
;
bool
_longPressAccepted
=
false
;
OffsetPair
_longPressOrigin
;
OffsetPair
?
_longPressOrigin
;
// The buttons sent by `PointerDownEvent`. If a `PointerMoveEvent` comes with a
// The buttons sent by `PointerDownEvent`. If a `PointerMoveEvent` comes with a
// different set of buttons, the gesture is canceled.
// different set of buttons, the gesture is canceled.
int
_initialButtons
;
int
?
_initialButtons
;
/// Called when a long press gesture by a primary button has been recognized.
/// Called when a long press gesture by a primary button has been recognized.
///
///
...
@@ -186,7 +185,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -186,7 +185,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [onLongPressStart], which has the same timing but has data for the
/// * [onLongPressStart], which has the same timing but has data for the
/// press location.
/// press location.
GestureLongPressCallback
onLongPress
;
GestureLongPressCallback
?
onLongPress
;
/// Called when a long press gesture by a primary button has been recognized.
/// Called when a long press gesture by a primary button has been recognized.
///
///
...
@@ -195,7 +194,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -195,7 +194,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [onLongPress], which has the same timing but without details.
/// * [onLongPress], which has the same timing but without details.
/// * [LongPressStartDetails], which is passed as an argument to this callback.
/// * [LongPressStartDetails], which is passed as an argument to this callback.
GestureLongPressStartCallback
onLongPressStart
;
GestureLongPressStartCallback
?
onLongPressStart
;
/// Called when moving after the long press by a primary button is recognized.
/// Called when moving after the long press by a primary button is recognized.
///
///
...
@@ -204,7 +203,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -204,7 +203,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [LongPressMoveUpdateDetails], which is passed as an argument to this
/// * [LongPressMoveUpdateDetails], which is passed as an argument to this
/// callback.
/// callback.
GestureLongPressMoveUpdateCallback
onLongPressMoveUpdate
;
GestureLongPressMoveUpdateCallback
?
onLongPressMoveUpdate
;
/// Called when the pointer stops contacting the screen after a long-press
/// Called when the pointer stops contacting the screen after a long-press
/// by a primary button.
/// by a primary button.
...
@@ -214,7 +213,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -214,7 +213,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [onLongPressEnd], which has the same timing but has data for the up
/// * [onLongPressEnd], which has the same timing but has data for the up
/// gesture location.
/// gesture location.
GestureLongPressUpCallback
onLongPressUp
;
GestureLongPressUpCallback
?
onLongPressUp
;
/// Called when the pointer stops contacting the screen after a long-press
/// Called when the pointer stops contacting the screen after a long-press
/// by a primary button.
/// by a primary button.
...
@@ -225,7 +224,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -225,7 +224,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [onLongPressUp], which has the same timing, but without details.
/// * [onLongPressUp], which has the same timing, but without details.
/// * [LongPressEndDetails], which is passed as an argument to this
/// * [LongPressEndDetails], which is passed as an argument to this
/// callback.
/// callback.
GestureLongPressEndCallback
onLongPressEnd
;
GestureLongPressEndCallback
?
onLongPressEnd
;
/// Called when a long press gesture by a secondary button has been
/// Called when a long press gesture by a secondary button has been
/// recognized.
/// recognized.
...
@@ -235,7 +234,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -235,7 +234,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kSecondaryButton], the button this callback responds to.
/// * [kSecondaryButton], the button this callback responds to.
/// * [onSecondaryLongPressStart], which has the same timing but has data for
/// * [onSecondaryLongPressStart], which has the same timing but has data for
/// the press location.
/// the press location.
GestureLongPressCallback
onSecondaryLongPress
;
GestureLongPressCallback
?
onSecondaryLongPress
;
/// Called when a long press gesture by a secondary button has been recognized.
/// Called when a long press gesture by a secondary button has been recognized.
///
///
...
@@ -245,7 +244,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -245,7 +244,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [onSecondaryLongPress], which has the same timing but without details.
/// * [onSecondaryLongPress], which has the same timing but without details.
/// * [LongPressStartDetails], which is passed as an argument to this
/// * [LongPressStartDetails], which is passed as an argument to this
/// callback.
/// callback.
GestureLongPressStartCallback
onSecondaryLongPressStart
;
GestureLongPressStartCallback
?
onSecondaryLongPressStart
;
/// Called when moving after the long press by a secondary button is
/// Called when moving after the long press by a secondary button is
/// recognized.
/// recognized.
...
@@ -255,7 +254,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -255,7 +254,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kSecondaryButton], the button this callback responds to.
/// * [kSecondaryButton], the button this callback responds to.
/// * [LongPressMoveUpdateDetails], which is passed as an argument to this
/// * [LongPressMoveUpdateDetails], which is passed as an argument to this
/// callback.
/// callback.
GestureLongPressMoveUpdateCallback
onSecondaryLongPressMoveUpdate
;
GestureLongPressMoveUpdateCallback
?
onSecondaryLongPressMoveUpdate
;
/// Called when the pointer stops contacting the screen after a long-press by
/// Called when the pointer stops contacting the screen after a long-press by
/// a secondary button.
/// a secondary button.
...
@@ -265,7 +264,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -265,7 +264,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [kSecondaryButton], the button this callback responds to.
/// * [kSecondaryButton], the button this callback responds to.
/// * [onSecondaryLongPressEnd], which has the same timing but has data for
/// * [onSecondaryLongPressEnd], which has the same timing but has data for
/// the up gesture location.
/// the up gesture location.
GestureLongPressUpCallback
onSecondaryLongPressUp
;
GestureLongPressUpCallback
?
onSecondaryLongPressUp
;
/// Called when the pointer stops contacting the screen after a long-press by
/// Called when the pointer stops contacting the screen after a long-press by
/// a secondary button.
/// a secondary button.
...
@@ -276,9 +275,9 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -276,9 +275,9 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// * [onSecondaryLongPressUp], which has the same timing, but without
/// * [onSecondaryLongPressUp], which has the same timing, but without
/// details.
/// details.
/// * [LongPressEndDetails], which is passed as an argument to this callback.
/// * [LongPressEndDetails], which is passed as an argument to this callback.
GestureLongPressEndCallback
onSecondaryLongPressEnd
;
GestureLongPressEndCallback
?
onSecondaryLongPressEnd
;
VelocityTracker
_velocityTracker
;
VelocityTracker
?
_velocityTracker
;
@override
@override
bool
isPointerAllowed
(
PointerDownEvent
event
)
{
bool
isPointerAllowed
(
PointerDownEvent
event
)
{
...
@@ -310,7 +309,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -310,7 +309,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
// Exceeding the deadline puts the gesture in the accepted state.
// Exceeding the deadline puts the gesture in the accepted state.
resolve
(
GestureDisposition
.
accepted
);
resolve
(
GestureDisposition
.
accepted
);
_longPressAccepted
=
true
;
_longPressAccepted
=
true
;
super
.
acceptGesture
(
primaryPointer
);
super
.
acceptGesture
(
primaryPointer
!
);
_checkLongPressStart
();
_checkLongPressStart
();
}
}
...
@@ -319,11 +318,11 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -319,11 +318,11 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
if
(!
event
.
synthesized
)
{
if
(!
event
.
synthesized
)
{
if
(
event
is
PointerDownEvent
)
{
if
(
event
is
PointerDownEvent
)
{
_velocityTracker
=
VelocityTracker
();
_velocityTracker
=
VelocityTracker
();
_velocityTracker
.
addPosition
(
event
.
timeStamp
,
event
.
localPosition
);
_velocityTracker
!
.
addPosition
(
event
.
timeStamp
,
event
.
localPosition
);
}
}
if
(
event
is
PointerMoveEvent
)
{
if
(
event
is
PointerMoveEvent
)
{
assert
(
_velocityTracker
!=
null
);
assert
(
_velocityTracker
!=
null
);
_velocityTracker
.
addPosition
(
event
.
timeStamp
,
event
.
localPosition
);
_velocityTracker
!
.
addPosition
(
event
.
timeStamp
,
event
.
localPosition
);
}
}
}
}
...
@@ -344,7 +343,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -344,7 +343,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
}
else
if
(
event
is
PointerMoveEvent
)
{
}
else
if
(
event
is
PointerMoveEvent
)
{
if
(
event
.
buttons
!=
_initialButtons
)
{
if
(
event
.
buttons
!=
_initialButtons
)
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
stopTrackingPointer
(
primaryPointer
);
stopTrackingPointer
(
primaryPointer
!
);
}
else
if
(
_longPressAccepted
)
{
}
else
if
(
_longPressAccepted
)
{
_checkLongPressMoveUpdate
(
event
);
_checkLongPressMoveUpdate
(
event
);
}
}
...
@@ -356,26 +355,26 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -356,26 +355,26 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
case
kPrimaryButton:
case
kPrimaryButton:
if
(
onLongPressStart
!=
null
)
{
if
(
onLongPressStart
!=
null
)
{
final
LongPressStartDetails
details
=
LongPressStartDetails
(
final
LongPressStartDetails
details
=
LongPressStartDetails
(
globalPosition:
_longPressOrigin
.
global
,
globalPosition:
_longPressOrigin
!
.
global
,
localPosition:
_longPressOrigin
.
local
,
localPosition:
_longPressOrigin
!
.
local
,
);
);
invokeCallback
<
void
>(
'onLongPressStart'
,
()
=>
onLongPressStart
(
details
));
invokeCallback
<
void
>(
'onLongPressStart'
,
()
=>
onLongPressStart
!
(
details
));
}
}
if
(
onLongPress
!=
null
)
{
if
(
onLongPress
!=
null
)
{
invokeCallback
<
void
>(
'onLongPress'
,
onLongPress
);
invokeCallback
<
void
>(
'onLongPress'
,
onLongPress
!
);
}
}
break
;
break
;
case
kSecondaryButton:
case
kSecondaryButton:
if
(
onSecondaryLongPressStart
!=
null
)
{
if
(
onSecondaryLongPressStart
!=
null
)
{
final
LongPressStartDetails
details
=
LongPressStartDetails
(
final
LongPressStartDetails
details
=
LongPressStartDetails
(
globalPosition:
_longPressOrigin
.
global
,
globalPosition:
_longPressOrigin
!
.
global
,
localPosition:
_longPressOrigin
.
local
,
localPosition:
_longPressOrigin
!
.
local
,
);
);
invokeCallback
<
void
>(
invokeCallback
<
void
>(
'onSecondaryLongPressStart'
,
()
=>
onSecondaryLongPressStart
(
details
));
'onSecondaryLongPressStart'
,
()
=>
onSecondaryLongPressStart
!
(
details
));
}
}
if
(
onSecondaryLongPress
!=
null
)
{
if
(
onSecondaryLongPress
!=
null
)
{
invokeCallback
<
void
>(
'onSecondaryLongPress'
,
onSecondaryLongPress
);
invokeCallback
<
void
>(
'onSecondaryLongPress'
,
onSecondaryLongPress
!
);
}
}
break
;
break
;
default
:
default
:
...
@@ -387,20 +386,20 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -387,20 +386,20 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
final
LongPressMoveUpdateDetails
details
=
LongPressMoveUpdateDetails
(
final
LongPressMoveUpdateDetails
details
=
LongPressMoveUpdateDetails
(
globalPosition:
event
.
position
,
globalPosition:
event
.
position
,
localPosition:
event
.
localPosition
,
localPosition:
event
.
localPosition
,
offsetFromOrigin:
event
.
position
-
_longPressOrigin
.
global
,
offsetFromOrigin:
event
.
position
-
_longPressOrigin
!
.
global
,
localOffsetFromOrigin:
event
.
localPosition
-
_longPressOrigin
.
local
,
localOffsetFromOrigin:
event
.
localPosition
-
_longPressOrigin
!
.
local
,
);
);
switch
(
_initialButtons
)
{
switch
(
_initialButtons
)
{
case
kPrimaryButton:
case
kPrimaryButton:
if
(
onLongPressMoveUpdate
!=
null
)
{
if
(
onLongPressMoveUpdate
!=
null
)
{
invokeCallback
<
void
>(
'onLongPressMoveUpdate'
,
invokeCallback
<
void
>(
'onLongPressMoveUpdate'
,
()
=>
onLongPressMoveUpdate
(
details
));
()
=>
onLongPressMoveUpdate
!
(
details
));
}
}
break
;
break
;
case
kSecondaryButton:
case
kSecondaryButton:
if
(
onSecondaryLongPressMoveUpdate
!=
null
)
{
if
(
onSecondaryLongPressMoveUpdate
!=
null
)
{
invokeCallback
<
void
>(
'onSecondaryLongPressMoveUpdate'
,
invokeCallback
<
void
>(
'onSecondaryLongPressMoveUpdate'
,
()
=>
onSecondaryLongPressMoveUpdate
(
details
));
()
=>
onSecondaryLongPressMoveUpdate
!
(
details
));
}
}
break
;
break
;
default
:
default
:
...
@@ -409,7 +408,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -409,7 +408,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
}
}
void
_checkLongPressEnd
(
PointerEvent
event
)
{
void
_checkLongPressEnd
(
PointerEvent
event
)
{
final
VelocityEstimate
estimate
=
_velocityTracker
.
getVelocityEstimate
();
final
VelocityEstimate
?
estimate
=
_velocityTracker
!
.
getVelocityEstimate
();
final
Velocity
velocity
=
estimate
==
null
final
Velocity
velocity
=
estimate
==
null
?
Velocity
.
zero
?
Velocity
.
zero
:
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
);
:
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
);
...
@@ -423,18 +422,18 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
...
@@ -423,18 +422,18 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
switch
(
_initialButtons
)
{
switch
(
_initialButtons
)
{
case
kPrimaryButton:
case
kPrimaryButton:
if
(
onLongPressEnd
!=
null
)
{
if
(
onLongPressEnd
!=
null
)
{
invokeCallback
<
void
>(
'onLongPressEnd'
,
()
=>
onLongPressEnd
(
details
));
invokeCallback
<
void
>(
'onLongPressEnd'
,
()
=>
onLongPressEnd
!
(
details
));
}
}
if
(
onLongPressUp
!=
null
)
{
if
(
onLongPressUp
!=
null
)
{
invokeCallback
<
void
>(
'onLongPressUp'
,
onLongPressUp
);
invokeCallback
<
void
>(
'onLongPressUp'
,
onLongPressUp
!
);
}
}
break
;
break
;
case
kSecondaryButton:
case
kSecondaryButton:
if
(
onSecondaryLongPressEnd
!=
null
)
{
if
(
onSecondaryLongPressEnd
!=
null
)
{
invokeCallback
<
void
>(
'onSecondaryLongPressEnd'
,
()
=>
onSecondaryLongPressEnd
(
details
));
invokeCallback
<
void
>(
'onSecondaryLongPressEnd'
,
()
=>
onSecondaryLongPressEnd
!
(
details
));
}
}
if
(
onSecondaryLongPressUp
!=
null
)
{
if
(
onSecondaryLongPressUp
!=
null
)
{
invokeCallback
<
void
>(
'onSecondaryLongPressUp'
,
onSecondaryLongPressUp
);
invokeCallback
<
void
>(
'onSecondaryLongPressUp'
,
onSecondaryLongPressUp
!
);
}
}
break
;
break
;
default
:
default
:
...
...
packages/flutter/lib/src/gestures/lsq_solver.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:math'
as
math
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'dart:typed_data'
;
...
@@ -76,7 +75,7 @@ class PolynomialFit {
...
@@ -76,7 +75,7 @@ class PolynomialFit {
/// An indicator of the quality of the fit.
/// An indicator of the quality of the fit.
///
///
/// Larger values indicate greater quality.
/// Larger values indicate greater quality.
double
confidence
;
late
double
confidence
;
}
}
/// Uses the least-squares algorithm to fit a polynomial to a set of data.
/// Uses the least-squares algorithm to fit a polynomial to a set of data.
...
@@ -98,7 +97,9 @@ class LeastSquaresSolver {
...
@@ -98,7 +97,9 @@ class LeastSquaresSolver {
final
List
<
double
>
w
;
final
List
<
double
>
w
;
/// Fits a polynomial of the given degree to the data points.
/// Fits a polynomial of the given degree to the data points.
PolynomialFit
solve
(
int
degree
)
{
///
/// When there is not enough data to fit a curve null is returned.
PolynomialFit
?
solve
(
int
degree
)
{
if
(
degree
>
x
.
length
)
// Not enough data to fit a curve.
if
(
degree
>
x
.
length
)
// Not enough data to fit a curve.
return
null
;
return
null
;
...
...
packages/flutter/lib/src/gestures/monodrag.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
...
@@ -62,8 +61,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -62,8 +61,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
DragGestureRecognizer
({
DragGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
})
:
assert
(
dragStartBehavior
!=
null
),
})
:
assert
(
dragStartBehavior
!=
null
),
super
(
debugOwner:
debugOwner
,
kind:
kind
);
super
(
debugOwner:
debugOwner
,
kind:
kind
);
...
@@ -101,7 +100,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -101,7 +100,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [DragDownDetails], which is passed as an argument to this callback.
/// * [DragDownDetails], which is passed as an argument to this callback.
GestureDragDownCallback
onDown
;
GestureDragDownCallback
?
onDown
;
/// A pointer has contacted the screen with a primary button and has begun to
/// A pointer has contacted the screen with a primary button and has begun to
/// move.
/// move.
...
@@ -118,7 +117,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -118,7 +117,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [DragStartDetails], which is passed as an argument to this callback.
/// * [DragStartDetails], which is passed as an argument to this callback.
GestureDragStartCallback
onStart
;
GestureDragStartCallback
?
onStart
;
/// A pointer that is in contact with the screen with a primary button and
/// A pointer that is in contact with the screen with a primary button and
/// moving has moved again.
/// moving has moved again.
...
@@ -130,7 +129,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -130,7 +129,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [DragUpdateDetails], which is passed as an argument to this callback.
/// * [DragUpdateDetails], which is passed as an argument to this callback.
GestureDragUpdateCallback
onUpdate
;
GestureDragUpdateCallback
?
onUpdate
;
/// A pointer that was previously in contact with the screen with a primary
/// A pointer that was previously in contact with the screen with a primary
/// button and moving is no longer in contact with the screen and was moving
/// button and moving is no longer in contact with the screen and was moving
...
@@ -143,48 +142,48 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -143,48 +142,48 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [DragEndDetails], which is passed as an argument to this callback.
/// * [DragEndDetails], which is passed as an argument to this callback.
GestureDragEndCallback
onEnd
;
GestureDragEndCallback
?
onEnd
;
/// The pointer that previously triggered [onDown] did not complete.
/// The pointer that previously triggered [onDown] did not complete.
///
///
/// See also:
/// See also:
///
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
GestureDragCancelCallback
onCancel
;
GestureDragCancelCallback
?
onCancel
;
/// The minimum distance an input pointer drag must have moved to
/// The minimum distance an input pointer drag must have moved to
/// to be considered a fling gesture.
/// to be considered a fling gesture.
///
///
/// This value is typically compared with the distance traveled along the
/// This value is typically compared with the distance traveled along the
/// scrolling axis. If null then [kTouchSlop] is used.
/// scrolling axis. If null then [kTouchSlop] is used.
double
minFlingDistance
;
double
?
minFlingDistance
;
/// The minimum velocity for an input pointer drag to be considered fling.
/// The minimum velocity for an input pointer drag to be considered fling.
///
///
/// This value is typically compared with the magnitude of fling gesture's
/// This value is typically compared with the magnitude of fling gesture's
/// velocity along the scrolling axis. If null then [kMinFlingVelocity]
/// velocity along the scrolling axis. If null then [kMinFlingVelocity]
/// is used.
/// is used.
double
minFlingVelocity
;
double
?
minFlingVelocity
;
/// Fling velocity magnitudes will be clamped to this value.
/// Fling velocity magnitudes will be clamped to this value.
///
///
/// If null then [kMaxFlingVelocity] is used.
/// If null then [kMaxFlingVelocity] is used.
double
maxFlingVelocity
;
double
?
maxFlingVelocity
;
_DragState
_state
=
_DragState
.
ready
;
_DragState
_state
=
_DragState
.
ready
;
OffsetPair
_initialPosition
;
late
OffsetPair
_initialPosition
;
OffsetPair
_pendingDragOffset
;
late
OffsetPair
_pendingDragOffset
;
Duration
_lastPendingEventTimestamp
;
Duration
?
_lastPendingEventTimestamp
;
// The buttons sent by `PointerDownEvent`. If a `PointerMoveEvent` comes with a
// The buttons sent by `PointerDownEvent`. If a `PointerMoveEvent` comes with a
// different set of buttons, the gesture is canceled.
// different set of buttons, the gesture is canceled.
int
_initialButtons
;
int
?
_initialButtons
;
Matrix4
_lastTransform
;
Matrix4
?
_lastTransform
;
/// Distance moved in the global coordinate space of the screen in drag direction.
/// Distance moved in the global coordinate space of the screen in drag direction.
///
///
/// If drag is only allowed along a defined axis, this value may be negative to
/// If drag is only allowed along a defined axis, this value may be negative to
/// differentiate the direction of the drag.
/// differentiate the direction of the drag.
double
_globalDistanceMoved
;
late
double
_globalDistanceMoved
;
/// Determines if a gesture is a fling or not based on velocity.
/// Determines if a gesture is a fling or not based on velocity.
///
///
...
@@ -194,7 +193,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -194,7 +193,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
bool
isFlingGesture
(
VelocityEstimate
estimate
);
bool
isFlingGesture
(
VelocityEstimate
estimate
);
Offset
_getDeltaForDetails
(
Offset
delta
);
Offset
_getDeltaForDetails
(
Offset
delta
);
double
_getPrimaryValueFromOffset
(
Offset
value
);
double
?
_getPrimaryValueFromOffset
(
Offset
value
);
bool
get
_hasSufficientGlobalDistanceToAccept
;
bool
get
_hasSufficientGlobalDistanceToAccept
;
final
Map
<
int
,
VelocityTracker
>
_velocityTrackers
=
<
int
,
VelocityTracker
>{};
final
Map
<
int
,
VelocityTracker
>
_velocityTrackers
=
<
int
,
VelocityTracker
>{};
...
@@ -246,7 +245,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -246,7 +245,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
assert
(
_state
!=
_DragState
.
ready
);
assert
(
_state
!=
_DragState
.
ready
);
if
(!
event
.
synthesized
if
(!
event
.
synthesized
&&
(
event
is
PointerDownEvent
||
event
is
PointerMoveEvent
))
{
&&
(
event
is
PointerDownEvent
||
event
is
PointerMoveEvent
))
{
final
VelocityTracker
tracker
=
_velocityTrackers
[
event
.
pointer
];
final
VelocityTracker
tracker
=
_velocityTrackers
[
event
.
pointer
]
!
;
assert
(
tracker
!=
null
);
assert
(
tracker
!=
null
);
tracker
.
addPosition
(
event
.
timeStamp
,
event
.
localPosition
);
tracker
.
addPosition
(
event
.
timeStamp
,
event
.
localPosition
);
}
}
...
@@ -269,7 +268,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -269,7 +268,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
_lastPendingEventTimestamp
=
event
.
timeStamp
;
_lastPendingEventTimestamp
=
event
.
timeStamp
;
_lastTransform
=
event
.
transform
;
_lastTransform
=
event
.
transform
;
final
Offset
movedLocally
=
_getDeltaForDetails
(
event
.
localDelta
);
final
Offset
movedLocally
=
_getDeltaForDetails
(
event
.
localDelta
);
final
Matrix4
localToGlobalTransform
=
event
.
transform
==
null
?
null
:
Matrix4
.
tryInvert
(
event
.
transform
);
final
Matrix4
?
localToGlobalTransform
=
event
.
transform
==
null
?
null
:
Matrix4
.
tryInvert
(
event
.
transform
!
);
_globalDistanceMoved
+=
PointerEvent
.
transformDeltaViaPositions
(
_globalDistanceMoved
+=
PointerEvent
.
transformDeltaViaPositions
(
transform:
localToGlobalTransform
,
transform:
localToGlobalTransform
,
untransformedDelta:
movedLocally
,
untransformedDelta:
movedLocally
,
...
@@ -292,8 +291,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -292,8 +291,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
_state
!=
_DragState
.
accepted
)
{
if
(
_state
!=
_DragState
.
accepted
)
{
_state
=
_DragState
.
accepted
;
_state
=
_DragState
.
accepted
;
final
OffsetPair
delta
=
_pendingDragOffset
;
final
OffsetPair
delta
=
_pendingDragOffset
;
final
Duration
timestamp
=
_lastPendingEventTimestamp
;
final
Duration
timestamp
=
_lastPendingEventTimestamp
!
;
final
Matrix4
transform
=
_lastTransform
;
final
Matrix4
?
transform
=
_lastTransform
;
Offset
localUpdateDelta
;
Offset
localUpdateDelta
;
switch
(
dragStartBehavior
)
{
switch
(
dragStartBehavior
)
{
case
DragStartBehavior
.
start
:
case
DragStartBehavior
.
start
:
...
@@ -309,7 +308,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -309,7 +308,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
_lastTransform
=
null
;
_lastTransform
=
null
;
_checkStart
(
timestamp
);
_checkStart
(
timestamp
);
if
(
localUpdateDelta
!=
Offset
.
zero
&&
onUpdate
!=
null
)
{
if
(
localUpdateDelta
!=
Offset
.
zero
&&
onUpdate
!=
null
)
{
final
Matrix4
localToGlobal
=
transform
!=
null
?
Matrix4
.
tryInvert
(
transform
)
:
null
;
final
Matrix4
?
localToGlobal
=
transform
!=
null
?
Matrix4
.
tryInvert
(
transform
)
:
null
;
final
Offset
correctedLocalPosition
=
_initialPosition
.
local
+
localUpdateDelta
;
final
Offset
correctedLocalPosition
=
_initialPosition
.
local
+
localUpdateDelta
;
final
Offset
globalUpdateDelta
=
PointerEvent
.
transformDeltaViaPositions
(
final
Offset
globalUpdateDelta
=
PointerEvent
.
transformDeltaViaPositions
(
untransformedEndPosition:
correctedLocalPosition
,
untransformedEndPosition:
correctedLocalPosition
,
...
@@ -372,7 +371,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -372,7 +371,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
localPosition:
_initialPosition
.
local
,
localPosition:
_initialPosition
.
local
,
);
);
if
(
onDown
!=
null
)
if
(
onDown
!=
null
)
invokeCallback
<
void
>(
'onDown'
,
()
=>
onDown
(
details
));
invokeCallback
<
void
>(
'onDown'
,
()
=>
onDown
!
(
details
));
}
}
void
_checkStart
(
Duration
timestamp
)
{
void
_checkStart
(
Duration
timestamp
)
{
...
@@ -383,15 +382,15 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -383,15 +382,15 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
localPosition:
_initialPosition
.
local
,
localPosition:
_initialPosition
.
local
,
);
);
if
(
onStart
!=
null
)
if
(
onStart
!=
null
)
invokeCallback
<
void
>(
'onStart'
,
()
=>
onStart
(
details
));
invokeCallback
<
void
>(
'onStart'
,
()
=>
onStart
!
(
details
));
}
}
void
_checkUpdate
({
void
_checkUpdate
({
Duration
sourceTimeStamp
,
Duration
?
sourceTimeStamp
,
Offset
delta
,
required
Offset
delta
,
double
primaryDelta
,
double
?
primaryDelta
,
Offset
globalPosition
,
required
Offset
globalPosition
,
Offset
localPosition
,
Offset
?
localPosition
,
})
{
})
{
assert
(
_initialButtons
==
kPrimaryButton
);
assert
(
_initialButtons
==
kPrimaryButton
);
final
DragUpdateDetails
details
=
DragUpdateDetails
(
final
DragUpdateDetails
details
=
DragUpdateDetails
(
...
@@ -402,7 +401,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -402,7 +401,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
localPosition:
localPosition
,
localPosition:
localPosition
,
);
);
if
(
onUpdate
!=
null
)
if
(
onUpdate
!=
null
)
invokeCallback
<
void
>(
'onUpdate'
,
()
=>
onUpdate
(
details
));
invokeCallback
<
void
>(
'onUpdate'
,
()
=>
onUpdate
!
(
details
));
}
}
void
_checkEnd
(
int
pointer
)
{
void
_checkEnd
(
int
pointer
)
{
...
@@ -410,13 +409,13 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -410,13 +409,13 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
onEnd
==
null
)
if
(
onEnd
==
null
)
return
;
return
;
final
VelocityTracker
tracker
=
_velocityTrackers
[
pointer
];
final
VelocityTracker
tracker
=
_velocityTrackers
[
pointer
]
!
;
assert
(
tracker
!=
null
);
assert
(
tracker
!=
null
);
DragEndDetails
details
;
DragEndDetails
details
;
String
Function
()
debugReport
;
String
Function
()
debugReport
;
final
VelocityEstimate
estimate
=
tracker
.
getVelocityEstimate
();
final
VelocityEstimate
?
estimate
=
tracker
.
getVelocityEstimate
();
if
(
estimate
!=
null
&&
isFlingGesture
(
estimate
))
{
if
(
estimate
!=
null
&&
isFlingGesture
(
estimate
))
{
final
Velocity
velocity
=
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
)
final
Velocity
velocity
=
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
)
.
clampMagnitude
(
minFlingVelocity
??
kMinFlingVelocity
,
maxFlingVelocity
??
kMaxFlingVelocity
);
.
clampMagnitude
(
minFlingVelocity
??
kMinFlingVelocity
,
maxFlingVelocity
??
kMaxFlingVelocity
);
...
@@ -438,13 +437,13 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -438,13 +437,13 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
return
'
$estimate
; judged to not be a fling.'
;
return
'
$estimate
; judged to not be a fling.'
;
};
};
}
}
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
(
details
),
debugReport:
debugReport
);
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
!
(
details
),
debugReport:
debugReport
);
}
}
void
_checkCancel
()
{
void
_checkCancel
()
{
assert
(
_initialButtons
==
kPrimaryButton
);
assert
(
_initialButtons
==
kPrimaryButton
);
if
(
onCancel
!=
null
)
if
(
onCancel
!=
null
)
invokeCallback
<
void
>(
'onCancel'
,
onCancel
);
invokeCallback
<
void
>(
'onCancel'
,
onCancel
!
);
}
}
@override
@override
...
@@ -474,8 +473,8 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
...
@@ -474,8 +473,8 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
VerticalDragGestureRecognizer
({
VerticalDragGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
@override
...
@@ -513,8 +512,8 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
...
@@ -513,8 +512,8 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
HorizontalDragGestureRecognizer
({
HorizontalDragGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
@override
...
@@ -548,7 +547,7 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
...
@@ -548,7 +547,7 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
/// some time has passed.
/// some time has passed.
class
PanGestureRecognizer
extends
DragGestureRecognizer
{
class
PanGestureRecognizer
extends
DragGestureRecognizer
{
/// Create a gesture recognizer for tracking movement on a plane.
/// Create a gesture recognizer for tracking movement on a plane.
PanGestureRecognizer
({
Object
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
PanGestureRecognizer
({
Object
?
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
@override
@override
bool
isFlingGesture
(
VelocityEstimate
estimate
)
{
bool
isFlingGesture
(
VelocityEstimate
estimate
)
{
...
@@ -567,7 +566,7 @@ class PanGestureRecognizer extends DragGestureRecognizer {
...
@@ -567,7 +566,7 @@ class PanGestureRecognizer extends DragGestureRecognizer {
Offset
_getDeltaForDetails
(
Offset
delta
)
=>
delta
;
Offset
_getDeltaForDetails
(
Offset
delta
)
=>
delta
;
@override
@override
double
_getPrimaryValueFromOffset
(
Offset
value
)
=>
null
;
double
?
_getPrimaryValueFromOffset
(
Offset
value
)
=>
null
;
@override
@override
String
get
debugDescription
=>
'pan'
;
String
get
debugDescription
=>
'pan'
;
...
...
packages/flutter/lib/src/gestures/multidrag.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'dart:async'
;
import
'dart:ui'
show
Offset
;
import
'dart:ui'
show
Offset
;
...
@@ -19,7 +18,7 @@ import 'recognizer.dart';
...
@@ -19,7 +18,7 @@ import 'recognizer.dart';
import
'velocity_tracker.dart'
;
import
'velocity_tracker.dart'
;
/// Signature for when [MultiDragGestureRecognizer] recognizes the start of a drag gesture.
/// Signature for when [MultiDragGestureRecognizer] recognizes the start of a drag gesture.
typedef
GestureMultiDragStartCallback
=
Drag
Function
(
Offset
position
);
typedef
GestureMultiDragStartCallback
=
Drag
?
Function
(
Offset
position
);
/// Per-pointer state for a [MultiDragGestureRecognizer].
/// Per-pointer state for a [MultiDragGestureRecognizer].
///
///
...
@@ -36,7 +35,7 @@ abstract class MultiDragPointerState {
...
@@ -36,7 +35,7 @@ abstract class MultiDragPointerState {
final
Offset
initialPosition
;
final
Offset
initialPosition
;
final
VelocityTracker
_velocityTracker
=
VelocityTracker
();
final
VelocityTracker
_velocityTracker
=
VelocityTracker
();
Drag
_client
;
Drag
?
_client
;
/// The offset of the pointer from the last position that was reported to the client.
/// The offset of the pointer from the last position that was reported to the client.
///
///
...
@@ -44,12 +43,12 @@ abstract class MultiDragPointerState {
...
@@ -44,12 +43,12 @@ abstract class MultiDragPointerState {
/// distance before this movement will be recognized as a drag. This field
/// distance before this movement will be recognized as a drag. This field
/// accumulates that movement so that we can report it to the client after
/// accumulates that movement so that we can report it to the client after
/// the drag starts.
/// the drag starts.
Offset
get
pendingDelta
=>
_pendingDelta
;
Offset
?
get
pendingDelta
=>
_pendingDelta
;
Offset
_pendingDelta
=
Offset
.
zero
;
Offset
?
_pendingDelta
=
Offset
.
zero
;
Duration
_lastPendingEventTimestamp
;
Duration
?
_lastPendingEventTimestamp
;
GestureArenaEntry
_arenaEntry
;
GestureArenaEntry
?
_arenaEntry
;
void
_setArenaEntry
(
GestureArenaEntry
entry
)
{
void
_setArenaEntry
(
GestureArenaEntry
entry
)
{
assert
(
_arenaEntry
==
null
);
assert
(
_arenaEntry
==
null
);
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
...
@@ -61,7 +60,7 @@ abstract class MultiDragPointerState {
...
@@ -61,7 +60,7 @@ abstract class MultiDragPointerState {
@protected
@protected
@mustCallSuper
@mustCallSuper
void
resolve
(
GestureDisposition
disposition
)
{
void
resolve
(
GestureDisposition
disposition
)
{
_arenaEntry
.
resolve
(
disposition
);
_arenaEntry
!
.
resolve
(
disposition
);
}
}
void
_move
(
PointerMoveEvent
event
)
{
void
_move
(
PointerMoveEvent
event
)
{
...
@@ -71,14 +70,14 @@ abstract class MultiDragPointerState {
...
@@ -71,14 +70,14 @@ abstract class MultiDragPointerState {
if
(
_client
!=
null
)
{
if
(
_client
!=
null
)
{
assert
(
pendingDelta
==
null
);
assert
(
pendingDelta
==
null
);
// Call client last to avoid reentrancy.
// Call client last to avoid reentrancy.
_client
.
update
(
DragUpdateDetails
(
_client
!
.
update
(
DragUpdateDetails
(
sourceTimeStamp:
event
.
timeStamp
,
sourceTimeStamp:
event
.
timeStamp
,
delta:
event
.
delta
,
delta:
event
.
delta
,
globalPosition:
event
.
position
,
globalPosition:
event
.
position
,
));
));
}
else
{
}
else
{
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
_pendingDelta
+=
event
.
delta
;
_pendingDelta
=
_pendingDelta
!
+
event
.
delta
;
_lastPendingEventTimestamp
=
event
.
timeStamp
;
_lastPendingEventTimestamp
=
event
.
timeStamp
;
checkForResolutionAfterMove
();
checkForResolutionAfterMove
();
}
}
...
@@ -119,13 +118,13 @@ abstract class MultiDragPointerState {
...
@@ -119,13 +118,13 @@ abstract class MultiDragPointerState {
_client
=
client
;
_client
=
client
;
final
DragUpdateDetails
details
=
DragUpdateDetails
(
final
DragUpdateDetails
details
=
DragUpdateDetails
(
sourceTimeStamp:
_lastPendingEventTimestamp
,
sourceTimeStamp:
_lastPendingEventTimestamp
,
delta:
pendingDelta
,
delta:
pendingDelta
!
,
globalPosition:
initialPosition
,
globalPosition:
initialPosition
,
);
);
_pendingDelta
=
null
;
_pendingDelta
=
null
;
_lastPendingEventTimestamp
=
null
;
_lastPendingEventTimestamp
=
null
;
// Call client last to avoid reentrancy.
// Call client last to avoid reentrancy.
_client
.
update
(
details
);
_client
!
.
update
(
details
);
}
}
void
_up
()
{
void
_up
()
{
...
@@ -133,7 +132,7 @@ abstract class MultiDragPointerState {
...
@@ -133,7 +132,7 @@ abstract class MultiDragPointerState {
if
(
_client
!=
null
)
{
if
(
_client
!=
null
)
{
assert
(
pendingDelta
==
null
);
assert
(
pendingDelta
==
null
);
final
DragEndDetails
details
=
DragEndDetails
(
velocity:
_velocityTracker
.
getVelocity
());
final
DragEndDetails
details
=
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.
client
.
end
(
details
);
client
.
end
(
details
);
...
@@ -148,7 +147,7 @@ abstract class MultiDragPointerState {
...
@@ -148,7 +147,7 @@ abstract class MultiDragPointerState {
assert
(
_arenaEntry
!=
null
);
assert
(
_arenaEntry
!=
null
);
if
(
_client
!=
null
)
{
if
(
_client
!=
null
)
{
assert
(
pendingDelta
==
null
);
assert
(
pendingDelta
==
null
);
final
Drag
client
=
_client
;
final
Drag
client
=
_client
!
;
_client
=
null
;
_client
=
null
;
// Call client last to avoid reentrancy.
// Call client last to avoid reentrancy.
client
.
cancel
();
client
.
cancel
();
...
@@ -195,28 +194,28 @@ abstract class MultiDragPointerState {
...
@@ -195,28 +194,28 @@ abstract class MultiDragPointerState {
abstract
class
MultiDragGestureRecognizer
<
T
extends
MultiDragPointerState
>
extends
GestureRecognizer
{
abstract
class
MultiDragGestureRecognizer
<
T
extends
MultiDragPointerState
>
extends
GestureRecognizer
{
/// Initialize the object.
/// Initialize the object.
MultiDragGestureRecognizer
({
MultiDragGestureRecognizer
({
@required
Object
debugOwner
,
required
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
/// Called when this class recognizes the start of a drag gesture.
/// Called when this class recognizes the start of a drag gesture.
///
///
/// The remaining notifications for this drag gesture are delivered to the
/// The remaining notifications for this drag gesture are delivered to the
/// [Drag] object returned by this callback.
/// [Drag] object returned by this callback.
GestureMultiDragStartCallback
onStart
;
GestureMultiDragStartCallback
?
onStart
;
Map
<
int
,
T
>
_pointers
=
<
int
,
T
>{};
Map
<
int
,
T
>
?
_pointers
=
<
int
,
T
>{};
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
assert
(
_pointers
!=
null
);
assert
(
_pointers
!=
null
);
assert
(
event
.
pointer
!=
null
);
assert
(
event
.
pointer
!=
null
);
assert
(
event
.
position
!=
null
);
assert
(
event
.
position
!=
null
);
assert
(!
_pointers
.
containsKey
(
event
.
pointer
));
assert
(!
_pointers
!
.
containsKey
(
event
.
pointer
));
final
T
state
=
createNewPointerState
(
event
);
final
T
state
=
createNewPointerState
(
event
);
_pointers
[
event
.
pointer
]
=
state
;
_pointers
!
[
event
.
pointer
]
=
state
;
GestureBinding
.
instance
.
pointerRouter
.
addRoute
(
event
.
pointer
,
_handleEvent
);
GestureBinding
.
instance
!
.
pointerRouter
.
addRoute
(
event
.
pointer
,
_handleEvent
);
state
.
_setArenaEntry
(
GestureBinding
.
instance
.
gestureArena
.
add
(
event
.
pointer
,
this
));
state
.
_setArenaEntry
(
GestureBinding
.
instance
!
.
gestureArena
.
add
(
event
.
pointer
,
this
));
}
}
/// Subclasses should override this method to create per-pointer state
/// Subclasses should override this method to create per-pointer state
...
@@ -230,8 +229,8 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
...
@@ -230,8 +229,8 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
assert
(
event
.
pointer
!=
null
);
assert
(
event
.
pointer
!=
null
);
assert
(
event
.
timeStamp
!=
null
);
assert
(
event
.
timeStamp
!=
null
);
assert
(
event
.
position
!=
null
);
assert
(
event
.
position
!=
null
);
assert
(
_pointers
.
containsKey
(
event
.
pointer
));
assert
(
_pointers
!
.
containsKey
(
event
.
pointer
));
final
T
state
=
_pointers
[
event
.
pointer
]
;
final
T
state
=
_pointers
![
event
.
pointer
]!
;
if
(
event
is
PointerMoveEvent
)
{
if
(
event
is
PointerMoveEvent
)
{
state
.
_move
(
event
);
state
.
_move
(
event
);
// We might be disposed here.
// We might be disposed here.
...
@@ -256,20 +255,20 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
...
@@ -256,20 +255,20 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
@override
@override
void
acceptGesture
(
int
pointer
)
{
void
acceptGesture
(
int
pointer
)
{
assert
(
_pointers
!=
null
);
assert
(
_pointers
!=
null
);
final
T
state
=
_pointers
[
pointer
];
final
T
?
state
=
_pointers
!
[
pointer
];
if
(
state
==
null
)
if
(
state
==
null
)
return
;
// We might already have canceled this drag if the up comes before the accept.
return
;
// We might already have canceled this drag if the up comes before the accept.
state
.
accepted
((
Offset
initialPosition
)
=>
_startDrag
(
initialPosition
,
pointer
));
state
.
accepted
((
Offset
initialPosition
)
=>
_startDrag
(
initialPosition
,
pointer
));
}
}
Drag
_startDrag
(
Offset
initialPosition
,
int
pointer
)
{
Drag
?
_startDrag
(
Offset
initialPosition
,
int
pointer
)
{
assert
(
_pointers
!=
null
);
assert
(
_pointers
!=
null
);
final
T
state
=
_pointers
[
pointer
]
;
final
T
state
=
_pointers
![
pointer
]!
;
assert
(
state
!=
null
);
assert
(
state
!=
null
);
assert
(
state
.
_pendingDelta
!=
null
);
assert
(
state
.
_pendingDelta
!=
null
);
Drag
drag
;
Drag
?
drag
;
if
(
onStart
!=
null
)
if
(
onStart
!=
null
)
drag
=
invokeCallback
<
Drag
>(
'onStart'
,
()
=>
onStart
(
initialPosition
));
drag
=
invokeCallback
<
Drag
?>(
'onStart'
,
()
=>
onStart
!
(
initialPosition
));
if
(
drag
!=
null
)
{
if
(
drag
!=
null
)
{
state
.
_startDrag
(
drag
);
state
.
_startDrag
(
drag
);
}
else
{
}
else
{
...
@@ -281,8 +280,8 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
...
@@ -281,8 +280,8 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
@override
@override
void
rejectGesture
(
int
pointer
)
{
void
rejectGesture
(
int
pointer
)
{
assert
(
_pointers
!=
null
);
assert
(
_pointers
!=
null
);
if
(
_pointers
.
containsKey
(
pointer
))
{
if
(
_pointers
!
.
containsKey
(
pointer
))
{
final
T
state
=
_pointers
[
pointer
]
;
final
T
state
=
_pointers
![
pointer
]!
;
assert
(
state
!=
null
);
assert
(
state
!=
null
);
state
.
rejected
();
state
.
rejected
();
_removeState
(
pointer
);
_removeState
(
pointer
);
...
@@ -295,15 +294,15 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
...
@@ -295,15 +294,15 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
// for the given pointer because dispose() has already removed it.
// for the given pointer because dispose() has already removed it.
return
;
return
;
}
}
assert
(
_pointers
.
containsKey
(
pointer
));
assert
(
_pointers
!
.
containsKey
(
pointer
));
GestureBinding
.
instance
.
pointerRouter
.
removeRoute
(
pointer
,
_handleEvent
);
GestureBinding
.
instance
!
.
pointerRouter
.
removeRoute
(
pointer
,
_handleEvent
);
_pointers
.
remove
(
pointer
)
.
dispose
();
_pointers
!.
remove
(
pointer
)!
.
dispose
();
}
}
@override
@override
void
dispose
()
{
void
dispose
()
{
_pointers
.
keys
.
toList
().
forEach
(
_removeState
);
_pointers
!
.
keys
.
toList
().
forEach
(
_removeState
);
assert
(
_pointers
.
isEmpty
);
assert
(
_pointers
!
.
isEmpty
);
_pointers
=
null
;
_pointers
=
null
;
super
.
dispose
();
super
.
dispose
();
}
}
...
@@ -315,7 +314,7 @@ class _ImmediatePointerState extends MultiDragPointerState {
...
@@ -315,7 +314,7 @@ class _ImmediatePointerState extends MultiDragPointerState {
@override
@override
void
checkForResolutionAfterMove
()
{
void
checkForResolutionAfterMove
()
{
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
if
(
pendingDelta
.
distance
>
kTouchSlop
)
if
(
pendingDelta
!
.
distance
>
kTouchSlop
)
resolve
(
GestureDisposition
.
accepted
);
resolve
(
GestureDisposition
.
accepted
);
}
}
...
@@ -344,8 +343,8 @@ class _ImmediatePointerState extends MultiDragPointerState {
...
@@ -344,8 +343,8 @@ class _ImmediatePointerState extends MultiDragPointerState {
class
ImmediateMultiDragGestureRecognizer
extends
MultiDragGestureRecognizer
<
_ImmediatePointerState
>
{
class
ImmediateMultiDragGestureRecognizer
extends
MultiDragGestureRecognizer
<
_ImmediatePointerState
>
{
/// Create a gesture recognizer for tracking multiple pointers at once.
/// Create a gesture recognizer for tracking multiple pointers at once.
ImmediateMultiDragGestureRecognizer
({
ImmediateMultiDragGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
@override
...
@@ -364,7 +363,7 @@ class _HorizontalPointerState extends MultiDragPointerState {
...
@@ -364,7 +363,7 @@ class _HorizontalPointerState extends MultiDragPointerState {
@override
@override
void
checkForResolutionAfterMove
()
{
void
checkForResolutionAfterMove
()
{
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
if
(
pendingDelta
.
dx
.
abs
()
>
kTouchSlop
)
if
(
pendingDelta
!
.
dx
.
abs
()
>
kTouchSlop
)
resolve
(
GestureDisposition
.
accepted
);
resolve
(
GestureDisposition
.
accepted
);
}
}
...
@@ -393,8 +392,8 @@ class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_H
...
@@ -393,8 +392,8 @@ class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_H
/// Create a gesture recognizer for tracking multiple pointers at once
/// Create a gesture recognizer for tracking multiple pointers at once
/// but only if they first move horizontally.
/// but only if they first move horizontally.
HorizontalMultiDragGestureRecognizer
({
HorizontalMultiDragGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
@override
...
@@ -413,7 +412,7 @@ class _VerticalPointerState extends MultiDragPointerState {
...
@@ -413,7 +412,7 @@ class _VerticalPointerState extends MultiDragPointerState {
@override
@override
void
checkForResolutionAfterMove
()
{
void
checkForResolutionAfterMove
()
{
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
if
(
pendingDelta
.
dy
.
abs
()
>
kTouchSlop
)
if
(
pendingDelta
!
.
dy
.
abs
()
>
kTouchSlop
)
resolve
(
GestureDisposition
.
accepted
);
resolve
(
GestureDisposition
.
accepted
);
}
}
...
@@ -442,8 +441,8 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Ver
...
@@ -442,8 +441,8 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Ver
/// Create a gesture recognizer for tracking multiple pointers at once
/// Create a gesture recognizer for tracking multiple pointers at once
/// but only if they first move vertically.
/// but only if they first move vertically.
VerticalMultiDragGestureRecognizer
({
VerticalMultiDragGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
@override
@override
...
@@ -462,16 +461,16 @@ class _DelayedPointerState extends MultiDragPointerState {
...
@@ -462,16 +461,16 @@ class _DelayedPointerState extends MultiDragPointerState {
_timer
=
Timer
(
delay
,
_delayPassed
);
_timer
=
Timer
(
delay
,
_delayPassed
);
}
}
Timer
_timer
;
Timer
?
_timer
;
GestureMultiDragStartCallback
_starter
;
GestureMultiDragStartCallback
?
_starter
;
void
_delayPassed
()
{
void
_delayPassed
()
{
assert
(
_timer
!=
null
);
assert
(
_timer
!=
null
);
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
.
distance
<=
kTouchSlop
);
assert
(
pendingDelta
!
.
distance
<=
kTouchSlop
);
_timer
=
null
;
_timer
=
null
;
if
(
_starter
!=
null
)
{
if
(
_starter
!=
null
)
{
_starter
(
initialPosition
);
_starter
!
(
initialPosition
);
_starter
=
null
;
_starter
=
null
;
}
else
{
}
else
{
resolve
(
GestureDisposition
.
accepted
);
resolve
(
GestureDisposition
.
accepted
);
...
@@ -505,7 +504,7 @@ class _DelayedPointerState extends MultiDragPointerState {
...
@@ -505,7 +504,7 @@ class _DelayedPointerState extends MultiDragPointerState {
return
;
return
;
}
}
assert
(
pendingDelta
!=
null
);
assert
(
pendingDelta
!=
null
);
if
(
pendingDelta
.
distance
>
kTouchSlop
)
{
if
(
pendingDelta
!
.
distance
>
kTouchSlop
)
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
_ensureTimerStopped
();
_ensureTimerStopped
();
}
}
...
@@ -545,8 +544,8 @@ class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Dela
...
@@ -545,8 +544,8 @@ class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Dela
/// can be changed for specific behaviors.
/// can be changed for specific behaviors.
DelayedMultiDragGestureRecognizer
({
DelayedMultiDragGestureRecognizer
({
this
.
delay
=
kLongPressTimeout
,
this
.
delay
=
kLongPressTimeout
,
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
assert
(
delay
!=
null
),
})
:
assert
(
delay
!=
null
),
super
(
debugOwner:
debugOwner
,
kind:
kind
);
super
(
debugOwner:
debugOwner
,
kind:
kind
);
...
...
packages/flutter/lib/src/gestures/multitap.dart
View file @
00dcd5f4
...
@@ -2,11 +2,9 @@
...
@@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'dart:async'
;
import
'dart:ui'
show
Offset
;
import
'dart:ui'
show
Offset
;
import
'package:flutter/foundation.dart'
show
required
;
import
'package:vector_math/vector_math_64.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
import
'arena.dart'
;
import
'arena.dart'
;
...
@@ -43,7 +41,7 @@ typedef GestureMultiTapCancelCallback = void Function(int pointer);
...
@@ -43,7 +41,7 @@ typedef GestureMultiTapCancelCallback = void Function(int pointer);
/// CountdownZoned tracks whether the specified duration has elapsed since
/// CountdownZoned tracks whether the specified duration has elapsed since
/// creation, honoring [Zone].
/// creation, honoring [Zone].
class
_CountdownZoned
{
class
_CountdownZoned
{
_CountdownZoned
({
@
required
Duration
duration
})
_CountdownZoned
({
required
Duration
duration
})
:
assert
(
duration
!=
null
)
{
:
assert
(
duration
!=
null
)
{
Timer
(
duration
,
_onTimeout
);
Timer
(
duration
,
_onTimeout
);
}
}
...
@@ -61,9 +59,9 @@ class _CountdownZoned {
...
@@ -61,9 +59,9 @@ class _CountdownZoned {
/// larger gesture.
/// larger gesture.
class
_TapTracker
{
class
_TapTracker
{
_TapTracker
({
_TapTracker
({
@
required
PointerDownEvent
event
,
required
PointerDownEvent
event
,
this
.
entry
,
this
.
entry
,
@
required
Duration
doubleTapMinTime
,
required
Duration
doubleTapMinTime
,
})
:
assert
(
doubleTapMinTime
!=
null
),
})
:
assert
(
doubleTapMinTime
!=
null
),
assert
(
event
!=
null
),
assert
(
event
!=
null
),
assert
(
event
.
buttons
!=
null
),
assert
(
event
.
buttons
!=
null
),
...
@@ -73,24 +71,24 @@ class _TapTracker {
...
@@ -73,24 +71,24 @@ class _TapTracker {
_doubleTapMinTimeCountdown
=
_CountdownZoned
(
duration:
doubleTapMinTime
);
_doubleTapMinTimeCountdown
=
_CountdownZoned
(
duration:
doubleTapMinTime
);
final
int
pointer
;
final
int
pointer
;
final
GestureArenaEntry
entry
;
final
GestureArenaEntry
?
entry
;
final
Offset
_initialGlobalPosition
;
final
Offset
_initialGlobalPosition
;
final
int
initialButtons
;
final
int
initialButtons
;
final
_CountdownZoned
_doubleTapMinTimeCountdown
;
final
_CountdownZoned
_doubleTapMinTimeCountdown
;
bool
_isTrackingPointer
=
false
;
bool
_isTrackingPointer
=
false
;
void
startTrackingPointer
(
PointerRoute
route
,
Matrix4
transform
)
{
void
startTrackingPointer
(
PointerRoute
route
,
Matrix4
?
transform
)
{
if
(!
_isTrackingPointer
)
{
if
(!
_isTrackingPointer
)
{
_isTrackingPointer
=
true
;
_isTrackingPointer
=
true
;
GestureBinding
.
instance
.
pointerRouter
.
addRoute
(
pointer
,
route
,
transform
);
GestureBinding
.
instance
!
.
pointerRouter
.
addRoute
(
pointer
,
route
,
transform
);
}
}
}
}
void
stopTrackingPointer
(
PointerRoute
route
)
{
void
stopTrackingPointer
(
PointerRoute
route
)
{
if
(
_isTrackingPointer
)
{
if
(
_isTrackingPointer
)
{
_isTrackingPointer
=
false
;
_isTrackingPointer
=
false
;
GestureBinding
.
instance
.
pointerRouter
.
removeRoute
(
pointer
,
route
);
GestureBinding
.
instance
!
.
pointerRouter
.
removeRoute
(
pointer
,
route
);
}
}
}
}
...
@@ -119,8 +117,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -119,8 +117,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
DoubleTapGestureRecognizer
({
DoubleTapGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
// Implementation notes:
// Implementation notes:
...
@@ -152,10 +150,10 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -152,10 +150,10 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
/// See also:
/// See also:
///
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
GestureDoubleTapCallback
onDoubleTap
;
GestureDoubleTapCallback
?
onDoubleTap
;
Timer
_doubleTapTimer
;
Timer
?
_doubleTapTimer
;
_TapTracker
_firstTap
;
_TapTracker
?
_firstTap
;
final
Map
<
int
,
_TapTracker
>
_trackers
=
<
int
,
_TapTracker
>{};
final
Map
<
int
,
_TapTracker
>
_trackers
=
<
int
,
_TapTracker
>{};
@override
@override
...
@@ -176,10 +174,10 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -176,10 +174,10 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
@override
@override
void
addAllowedPointer
(
PointerEvent
event
)
{
void
addAllowedPointer
(
PointerEvent
event
)
{
if
(
_firstTap
!=
null
)
{
if
(
_firstTap
!=
null
)
{
if
(!
_firstTap
.
isWithinGlobalTolerance
(
event
,
kDoubleTapSlop
))
{
if
(!
_firstTap
!
.
isWithinGlobalTolerance
(
event
,
kDoubleTapSlop
))
{
// Ignore out-of-bounds second taps.
// Ignore out-of-bounds second taps.
return
;
return
;
}
else
if
(!
_firstTap
.
hasElapsedMinTime
()
||
!
_firstTap
.
hasSameButton
(
event
as
PointerDownEvent
))
{
}
else
if
(!
_firstTap
!.
hasElapsedMinTime
()
||
!
_firstTap
!
.
hasSameButton
(
event
as
PointerDownEvent
))
{
// Restart when the second tap is too close to the first, or when buttons
// Restart when the second tap is too close to the first, or when buttons
// mismatch.
// mismatch.
_reset
();
_reset
();
...
@@ -193,7 +191,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -193,7 +191,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
_stopDoubleTapTimer
();
_stopDoubleTapTimer
();
final
_TapTracker
tracker
=
_TapTracker
(
final
_TapTracker
tracker
=
_TapTracker
(
event:
event
as
PointerDownEvent
,
event:
event
as
PointerDownEvent
,
entry:
GestureBinding
.
instance
.
gestureArena
.
add
(
event
.
pointer
,
this
),
entry:
GestureBinding
.
instance
!
.
gestureArena
.
add
(
event
.
pointer
,
this
),
doubleTapMinTime:
kDoubleTapMinTime
,
doubleTapMinTime:
kDoubleTapMinTime
,
);
);
_trackers
[
event
.
pointer
]
=
tracker
;
_trackers
[
event
.
pointer
]
=
tracker
;
...
@@ -201,8 +199,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -201,8 +199,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
}
}
void
_handleEvent
(
PointerEvent
event
)
{
void
_handleEvent
(
PointerEvent
event
)
{
final
_TapTracker
tracker
=
_trackers
[
event
.
pointer
];
final
_TapTracker
tracker
=
_trackers
[
event
.
pointer
]!;
assert
(
tracker
!=
null
);
if
(
event
is
PointerUpEvent
)
{
if
(
event
is
PointerUpEvent
)
{
if
(
_firstTap
==
null
)
if
(
_firstTap
==
null
)
_registerFirstTap
(
tracker
);
_registerFirstTap
(
tracker
);
...
@@ -221,11 +218,11 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -221,11 +218,11 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
@override
@override
void
rejectGesture
(
int
pointer
)
{
void
rejectGesture
(
int
pointer
)
{
_TapTracker
tracker
=
_trackers
[
pointer
];
_TapTracker
?
tracker
=
_trackers
[
pointer
];
// If tracker isn't in the list, check if this is the first tap tracker
// If tracker isn't in the list, check if this is the first tap tracker
if
(
tracker
==
null
&&
if
(
tracker
==
null
&&
_firstTap
!=
null
&&
_firstTap
!=
null
&&
_firstTap
.
pointer
==
pointer
)
_firstTap
!
.
pointer
==
pointer
)
tracker
=
_firstTap
;
tracker
=
_firstTap
;
// If tracker is still null, we rejected ourselves already
// If tracker is still null, we rejected ourselves already
if
(
tracker
!=
null
)
if
(
tracker
!=
null
)
...
@@ -234,7 +231,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -234,7 +231,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
void
_reject
(
_TapTracker
tracker
)
{
void
_reject
(
_TapTracker
tracker
)
{
_trackers
.
remove
(
tracker
.
pointer
);
_trackers
.
remove
(
tracker
.
pointer
);
tracker
.
entry
.
resolve
(
GestureDisposition
.
rejected
);
tracker
.
entry
!
.
resolve
(
GestureDisposition
.
rejected
);
_freezeTracker
(
tracker
);
_freezeTracker
(
tracker
);
// If the first tap is in progress, and we've run out of taps to track,
// If the first tap is in progress, and we've run out of taps to track,
// reset won't have any work to do. But if we're in the second tap, we need
// reset won't have any work to do. But if we're in the second tap, we need
...
@@ -255,17 +252,17 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -255,17 +252,17 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
if
(
_firstTap
!=
null
)
{
if
(
_firstTap
!=
null
)
{
// Note, order is important below in order for the resolve -> reject logic
// Note, order is important below in order for the resolve -> reject logic
// to work properly.
// to work properly.
final
_TapTracker
tracker
=
_firstTap
;
final
_TapTracker
tracker
=
_firstTap
!
;
_firstTap
=
null
;
_firstTap
=
null
;
_reject
(
tracker
);
_reject
(
tracker
);
GestureBinding
.
instance
.
gestureArena
.
release
(
tracker
.
pointer
);
GestureBinding
.
instance
!
.
gestureArena
.
release
(
tracker
.
pointer
);
}
}
_clearTrackers
();
_clearTrackers
();
}
}
void
_registerFirstTap
(
_TapTracker
tracker
)
{
void
_registerFirstTap
(
_TapTracker
tracker
)
{
_startDoubleTapTimer
();
_startDoubleTapTimer
();
GestureBinding
.
instance
.
gestureArena
.
hold
(
tracker
.
pointer
);
GestureBinding
.
instance
!
.
gestureArena
.
hold
(
tracker
.
pointer
);
// Note, order is important below in order for the clear -> reject logic to
// Note, order is important below in order for the clear -> reject logic to
// work properly.
// work properly.
_freezeTracker
(
tracker
);
_freezeTracker
(
tracker
);
...
@@ -275,8 +272,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -275,8 +272,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
}
}
void
_registerSecondTap
(
_TapTracker
tracker
)
{
void
_registerSecondTap
(
_TapTracker
tracker
)
{
_firstTap
.
entry
.
resolve
(
GestureDisposition
.
accepted
);
_firstTap
!.
entry
!
.
resolve
(
GestureDisposition
.
accepted
);
tracker
.
entry
.
resolve
(
GestureDisposition
.
accepted
);
tracker
.
entry
!
.
resolve
(
GestureDisposition
.
accepted
);
_freezeTracker
(
tracker
);
_freezeTracker
(
tracker
);
_trackers
.
remove
(
tracker
.
pointer
);
_trackers
.
remove
(
tracker
.
pointer
);
_checkUp
(
tracker
.
initialButtons
);
_checkUp
(
tracker
.
initialButtons
);
...
@@ -298,7 +295,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -298,7 +295,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
void
_stopDoubleTapTimer
()
{
void
_stopDoubleTapTimer
()
{
if
(
_doubleTapTimer
!=
null
)
{
if
(
_doubleTapTimer
!=
null
)
{
_doubleTapTimer
.
cancel
();
_doubleTapTimer
!
.
cancel
();
_doubleTapTimer
=
null
;
_doubleTapTimer
=
null
;
}
}
}
}
...
@@ -306,7 +303,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -306,7 +303,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
void
_checkUp
(
int
buttons
)
{
void
_checkUp
(
int
buttons
)
{
assert
(
buttons
==
kPrimaryButton
);
assert
(
buttons
==
kPrimaryButton
);
if
(
onDoubleTap
!=
null
)
if
(
onDoubleTap
!=
null
)
invokeCallback
<
void
>(
'onDoubleTap'
,
onDoubleTap
);
invokeCallback
<
void
>(
'onDoubleTap'
,
onDoubleTap
!
);
}
}
@override
@override
...
@@ -319,13 +316,13 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
...
@@ -319,13 +316,13 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
class
_TapGesture
extends
_TapTracker
{
class
_TapGesture
extends
_TapTracker
{
_TapGesture
({
_TapGesture
({
this
.
gestureRecognizer
,
required
this
.
gestureRecognizer
,
PointerEvent
event
,
required
PointerEvent
event
,
Duration
longTapDelay
,
required
Duration
longTapDelay
,
})
:
_lastPosition
=
OffsetPair
.
fromEventPosition
(
event
),
})
:
_lastPosition
=
OffsetPair
.
fromEventPosition
(
event
),
super
(
super
(
event:
event
as
PointerDownEvent
,
event:
event
as
PointerDownEvent
,
entry:
GestureBinding
.
instance
.
gestureArena
.
add
(
event
.
pointer
,
gestureRecognizer
),
entry:
GestureBinding
.
instance
!
.
gestureArena
.
add
(
event
.
pointer
,
gestureRecognizer
),
doubleTapMinTime:
kDoubleTapMinTime
,
doubleTapMinTime:
kDoubleTapMinTime
,
)
{
)
{
startTrackingPointer
(
handleEvent
,
event
.
transform
);
startTrackingPointer
(
handleEvent
,
event
.
transform
);
...
@@ -340,10 +337,10 @@ class _TapGesture extends _TapTracker {
...
@@ -340,10 +337,10 @@ class _TapGesture extends _TapTracker {
final
MultiTapGestureRecognizer
gestureRecognizer
;
final
MultiTapGestureRecognizer
gestureRecognizer
;
bool
_wonArena
=
false
;
bool
_wonArena
=
false
;
Timer
_timer
;
Timer
?
_timer
;
OffsetPair
_lastPosition
;
OffsetPair
_lastPosition
;
OffsetPair
_finalPosition
;
OffsetPair
?
_finalPosition
;
void
handleEvent
(
PointerEvent
event
)
{
void
handleEvent
(
PointerEvent
event
)
{
assert
(
event
.
pointer
==
pointer
);
assert
(
event
.
pointer
==
pointer
);
...
@@ -384,12 +381,12 @@ class _TapGesture extends _TapTracker {
...
@@ -384,12 +381,12 @@ class _TapGesture extends _TapTracker {
if
(
_wonArena
)
if
(
_wonArena
)
reject
();
reject
();
else
else
entry
.
resolve
(
GestureDisposition
.
rejected
);
// eventually calls reject()
entry
!
.
resolve
(
GestureDisposition
.
rejected
);
// eventually calls reject()
}
}
void
_check
()
{
void
_check
()
{
if
(
_wonArena
&&
_finalPosition
!=
null
)
if
(
_wonArena
&&
_finalPosition
!=
null
)
gestureRecognizer
.
_dispatchTap
(
pointer
,
_finalPosition
);
gestureRecognizer
.
_dispatchTap
(
pointer
,
_finalPosition
!
);
}
}
}
}
...
@@ -409,31 +406,31 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
...
@@ -409,31 +406,31 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
/// [onLongTapDown] is called immediately after [onTapDown].
/// [onLongTapDown] is called immediately after [onTapDown].
MultiTapGestureRecognizer
({
MultiTapGestureRecognizer
({
this
.
longTapDelay
=
Duration
.
zero
,
this
.
longTapDelay
=
Duration
.
zero
,
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
/// A pointer that might cause a tap has contacted the screen at a particular
/// A pointer that might cause a tap has contacted the screen at a particular
/// location.
/// location.
GestureMultiTapDownCallback
onTapDown
;
GestureMultiTapDownCallback
?
onTapDown
;
/// A pointer that will trigger a tap has stopped contacting the screen at a
/// A pointer that will trigger a tap has stopped contacting the screen at a
/// particular location.
/// particular location.
GestureMultiTapUpCallback
onTapUp
;
GestureMultiTapUpCallback
?
onTapUp
;
/// A tap has occurred.
/// A tap has occurred.
GestureMultiTapCallback
onTap
;
GestureMultiTapCallback
?
onTap
;
/// The pointer that previously triggered [onTapDown] will not end up causing
/// The pointer that previously triggered [onTapDown] will not end up causing
/// a tap.
/// a tap.
GestureMultiTapCancelCallback
onTapCancel
;
GestureMultiTapCancelCallback
?
onTapCancel
;
/// The amount of time between [onTapDown] and [onLongTapDown].
/// The amount of time between [onTapDown] and [onLongTapDown].
Duration
longTapDelay
;
Duration
longTapDelay
;
/// A pointer that might cause a tap is still in contact with the screen at a
/// A pointer that might cause a tap is still in contact with the screen at a
/// particular location after [longTapDelay].
/// particular location after [longTapDelay].
GestureMultiTapDownCallback
onLongTapDown
;
GestureMultiTapDownCallback
?
onLongTapDown
;
final
Map
<
int
,
_TapGesture
>
_gestureMap
=
<
int
,
_TapGesture
>{};
final
Map
<
int
,
_TapGesture
>
_gestureMap
=
<
int
,
_TapGesture
>{};
...
@@ -447,7 +444,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
...
@@ -447,7 +444,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
);
);
if
(
onTapDown
!=
null
)
if
(
onTapDown
!=
null
)
invokeCallback
<
void
>(
'onTapDown'
,
()
{
invokeCallback
<
void
>(
'onTapDown'
,
()
{
onTapDown
(
event
.
pointer
,
TapDownDetails
(
onTapDown
!
(
event
.
pointer
,
TapDownDetails
(
globalPosition:
event
.
position
,
globalPosition:
event
.
position
,
localPosition:
event
.
localPosition
,
localPosition:
event
.
localPosition
,
kind:
event
.
kind
,
kind:
event
.
kind
,
...
@@ -458,13 +455,13 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
...
@@ -458,13 +455,13 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
@override
@override
void
acceptGesture
(
int
pointer
)
{
void
acceptGesture
(
int
pointer
)
{
assert
(
_gestureMap
.
containsKey
(
pointer
));
assert
(
_gestureMap
.
containsKey
(
pointer
));
_gestureMap
[
pointer
].
accept
();
_gestureMap
[
pointer
]
!
.
accept
();
}
}
@override
@override
void
rejectGesture
(
int
pointer
)
{
void
rejectGesture
(
int
pointer
)
{
assert
(
_gestureMap
.
containsKey
(
pointer
));
assert
(
_gestureMap
.
containsKey
(
pointer
));
_gestureMap
[
pointer
].
reject
();
_gestureMap
[
pointer
]
!
.
reject
();
assert
(!
_gestureMap
.
containsKey
(
pointer
));
assert
(!
_gestureMap
.
containsKey
(
pointer
));
}
}
...
@@ -472,7 +469,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
...
@@ -472,7 +469,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
assert
(
_gestureMap
.
containsKey
(
pointer
));
assert
(
_gestureMap
.
containsKey
(
pointer
));
_gestureMap
.
remove
(
pointer
);
_gestureMap
.
remove
(
pointer
);
if
(
onTapCancel
!=
null
)
if
(
onTapCancel
!=
null
)
invokeCallback
<
void
>(
'onTapCancel'
,
()
=>
onTapCancel
(
pointer
));
invokeCallback
<
void
>(
'onTapCancel'
,
()
=>
onTapCancel
!
(
pointer
));
}
}
void
_dispatchTap
(
int
pointer
,
OffsetPair
position
)
{
void
_dispatchTap
(
int
pointer
,
OffsetPair
position
)
{
...
@@ -480,20 +477,20 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
...
@@ -480,20 +477,20 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
_gestureMap
.
remove
(
pointer
);
_gestureMap
.
remove
(
pointer
);
if
(
onTapUp
!=
null
)
if
(
onTapUp
!=
null
)
invokeCallback
<
void
>(
'onTapUp'
,
()
{
invokeCallback
<
void
>(
'onTapUp'
,
()
{
onTapUp
(
pointer
,
TapUpDetails
(
onTapUp
!
(
pointer
,
TapUpDetails
(
localPosition:
position
.
local
,
localPosition:
position
.
local
,
globalPosition:
position
.
global
,
globalPosition:
position
.
global
,
));
));
});
});
if
(
onTap
!=
null
)
if
(
onTap
!=
null
)
invokeCallback
<
void
>(
'onTap'
,
()
=>
onTap
(
pointer
));
invokeCallback
<
void
>(
'onTap'
,
()
=>
onTap
!
(
pointer
));
}
}
void
_dispatchLongTap
(
int
pointer
,
OffsetPair
lastPosition
)
{
void
_dispatchLongTap
(
int
pointer
,
OffsetPair
lastPosition
)
{
assert
(
_gestureMap
.
containsKey
(
pointer
));
assert
(
_gestureMap
.
containsKey
(
pointer
));
if
(
onLongTapDown
!=
null
)
if
(
onLongTapDown
!=
null
)
invokeCallback
<
void
>(
'onLongTapDown'
,
()
{
invokeCallback
<
void
>(
'onLongTapDown'
,
()
{
onLongTapDown
(
onLongTapDown
!
(
pointer
,
pointer
,
TapDownDetails
(
TapDownDetails
(
globalPosition:
lastPosition
.
global
,
globalPosition:
lastPosition
.
global
,
...
...
packages/flutter/lib/src/gestures/pointer_router.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
...
@@ -14,8 +13,8 @@ typedef PointerRoute = void Function(PointerEvent event);
...
@@ -14,8 +13,8 @@ typedef PointerRoute = void Function(PointerEvent event);
/// A routing table for [PointerEvent] events.
/// A routing table for [PointerEvent] events.
class
PointerRouter
{
class
PointerRouter
{
final
Map
<
int
,
Map
<
PointerRoute
,
Matrix4
>>
_routeMap
=
<
int
,
Map
<
PointerRoute
,
Matrix4
>>{};
final
Map
<
int
,
Map
<
PointerRoute
,
Matrix4
?>>
_routeMap
=
<
int
,
Map
<
PointerRoute
,
Matrix4
?
>>{};
final
Map
<
PointerRoute
,
Matrix4
>
_globalRoutes
=
<
PointerRoute
,
Matrix4
>{};
final
Map
<
PointerRoute
,
Matrix4
?>
_globalRoutes
=
<
PointerRoute
,
Matrix4
?
>{};
/// Adds a route to the routing table.
/// Adds a route to the routing table.
///
///
...
@@ -24,10 +23,10 @@ class PointerRouter {
...
@@ -24,10 +23,10 @@ class PointerRouter {
///
///
/// Routes added reentrantly within [PointerRouter.route] will take effect when
/// Routes added reentrantly within [PointerRouter.route] will take effect when
/// routing the next event.
/// routing the next event.
void
addRoute
(
int
pointer
,
PointerRoute
route
,
[
Matrix4
transform
])
{
void
addRoute
(
int
pointer
,
PointerRoute
route
,
[
Matrix4
?
transform
])
{
final
Map
<
PointerRoute
,
Matrix4
>
routes
=
_routeMap
.
putIfAbsent
(
final
Map
<
PointerRoute
,
Matrix4
?
>
routes
=
_routeMap
.
putIfAbsent
(
pointer
,
pointer
,
()
=>
<
PointerRoute
,
Matrix4
>{},
()
=>
<
PointerRoute
,
Matrix4
?
>{},
);
);
assert
(!
routes
.
containsKey
(
route
));
assert
(!
routes
.
containsKey
(
route
));
routes
[
route
]
=
transform
;
routes
[
route
]
=
transform
;
...
@@ -42,7 +41,7 @@ class PointerRouter {
...
@@ -42,7 +41,7 @@ class PointerRouter {
/// immediately.
/// immediately.
void
removeRoute
(
int
pointer
,
PointerRoute
route
)
{
void
removeRoute
(
int
pointer
,
PointerRoute
route
)
{
assert
(
_routeMap
.
containsKey
(
pointer
));
assert
(
_routeMap
.
containsKey
(
pointer
));
final
Map
<
PointerRoute
,
Matrix4
>
routes
=
_routeMap
[
pointer
]
;
final
Map
<
PointerRoute
,
Matrix4
?>
routes
=
_routeMap
[
pointer
]!
;
assert
(
routes
.
containsKey
(
route
));
assert
(
routes
.
containsKey
(
route
));
routes
.
remove
(
route
);
routes
.
remove
(
route
);
if
(
routes
.
isEmpty
)
if
(
routes
.
isEmpty
)
...
@@ -55,7 +54,7 @@ class PointerRouter {
...
@@ -55,7 +54,7 @@ class PointerRouter {
///
///
/// Routes added reentrantly within [PointerRouter.route] will take effect when
/// Routes added reentrantly within [PointerRouter.route] will take effect when
/// routing the next event.
/// routing the next event.
void
addGlobalRoute
(
PointerRoute
route
,
[
Matrix4
transform
])
{
void
addGlobalRoute
(
PointerRoute
route
,
[
Matrix4
?
transform
])
{
assert
(!
_globalRoutes
.
containsKey
(
route
));
assert
(!
_globalRoutes
.
containsKey
(
route
));
_globalRoutes
[
route
]
=
transform
;
_globalRoutes
[
route
]
=
transform
;
}
}
...
@@ -72,12 +71,12 @@ class PointerRouter {
...
@@ -72,12 +71,12 @@ class PointerRouter {
_globalRoutes
.
remove
(
route
);
_globalRoutes
.
remove
(
route
);
}
}
void
_dispatch
(
PointerEvent
event
,
PointerRoute
route
,
Matrix4
transform
)
{
void
_dispatch
(
PointerEvent
event
,
PointerRoute
route
,
Matrix4
?
transform
)
{
try
{
try
{
event
=
event
.
transformed
(
transform
);
event
=
event
.
transformed
(
transform
);
route
(
event
);
route
(
event
);
}
catch
(
exception
,
stack
)
{
}
catch
(
exception
,
stack
)
{
InformationCollector
collector
;
InformationCollector
?
collector
;
assert
(()
{
assert
(()
{
collector
=
()
sync
*
{
collector
=
()
sync
*
{
yield
DiagnosticsProperty
<
PointerRouter
>(
'router'
,
this
,
level:
DiagnosticLevel
.
debug
);
yield
DiagnosticsProperty
<
PointerRouter
>(
'router'
,
this
,
level:
DiagnosticLevel
.
debug
);
...
@@ -101,13 +100,13 @@ class PointerRouter {
...
@@ -101,13 +100,13 @@ class PointerRouter {
/// Routes are called in the order in which they were added to the
/// Routes are called in the order in which they were added to the
/// PointerRouter object.
/// PointerRouter object.
void
route
(
PointerEvent
event
)
{
void
route
(
PointerEvent
event
)
{
final
Map
<
PointerRoute
,
Matrix4
>
routes
=
_routeMap
[
event
.
pointer
];
final
Map
<
PointerRoute
,
Matrix4
?>?
routes
=
_routeMap
[
event
.
pointer
];
final
Map
<
PointerRoute
,
Matrix4
>
copiedGlobalRoutes
=
Map
<
PointerRoute
,
Matrix4
>.
from
(
_globalRoutes
);
final
Map
<
PointerRoute
,
Matrix4
?>
copiedGlobalRoutes
=
Map
<
PointerRoute
,
Matrix4
?
>.
from
(
_globalRoutes
);
if
(
routes
!=
null
)
{
if
(
routes
!=
null
)
{
_dispatchEventToRoutes
(
_dispatchEventToRoutes
(
event
,
event
,
routes
,
routes
,
Map
<
PointerRoute
,
Matrix4
>.
from
(
routes
),
Map
<
PointerRoute
,
Matrix4
?
>.
from
(
routes
),
);
);
}
}
_dispatchEventToRoutes
(
event
,
_globalRoutes
,
copiedGlobalRoutes
);
_dispatchEventToRoutes
(
event
,
_globalRoutes
,
copiedGlobalRoutes
);
...
@@ -115,10 +114,10 @@ class PointerRouter {
...
@@ -115,10 +114,10 @@ class PointerRouter {
void
_dispatchEventToRoutes
(
void
_dispatchEventToRoutes
(
PointerEvent
event
,
PointerEvent
event
,
Map
<
PointerRoute
,
Matrix4
>
referenceRoutes
,
Map
<
PointerRoute
,
Matrix4
?
>
referenceRoutes
,
Map
<
PointerRoute
,
Matrix4
>
copiedRoutes
,
Map
<
PointerRoute
,
Matrix4
?
>
copiedRoutes
,
)
{
)
{
copiedRoutes
.
forEach
((
PointerRoute
route
,
Matrix4
transform
)
{
copiedRoutes
.
forEach
((
PointerRoute
route
,
Matrix4
?
transform
)
{
if
(
referenceRoutes
.
containsKey
(
route
))
{
if
(
referenceRoutes
.
containsKey
(
route
))
{
_dispatch
(
event
,
route
,
transform
);
_dispatch
(
event
,
route
,
transform
);
}
}
...
...
packages/flutter/lib/src/gestures/pointer_signal_resolver.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
...
@@ -27,15 +26,15 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
...
@@ -27,15 +26,15 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
/// at the end of event dispatch. The first callback registered will be the one
/// at the end of event dispatch. The first callback registered will be the one
/// that is called.
/// that is called.
class
PointerSignalResolver
{
class
PointerSignalResolver
{
PointerSignalResolvedCallback
_firstRegisteredCallback
;
PointerSignalResolvedCallback
?
_firstRegisteredCallback
;
PointerSignalEvent
_currentEvent
;
PointerSignalEvent
?
_currentEvent
;
/// Registers interest in handling [event].
/// Registers interest in handling [event].
void
register
(
PointerSignalEvent
event
,
PointerSignalResolvedCallback
callback
)
{
void
register
(
PointerSignalEvent
event
,
PointerSignalResolvedCallback
callback
)
{
assert
(
event
!=
null
);
assert
(
event
!=
null
);
assert
(
callback
!=
null
);
assert
(
callback
!=
null
);
assert
(
_currentEvent
==
null
||
_isSameEvent
(
_currentEvent
,
event
));
assert
(
_currentEvent
==
null
||
_isSameEvent
(
_currentEvent
!
,
event
));
if
(
_firstRegisteredCallback
!=
null
)
{
if
(
_firstRegisteredCallback
!=
null
)
{
return
;
return
;
}
}
...
@@ -53,11 +52,11 @@ class PointerSignalResolver {
...
@@ -53,11 +52,11 @@ class PointerSignalResolver {
assert
(
_currentEvent
==
null
);
assert
(
_currentEvent
==
null
);
return
;
return
;
}
}
assert
(
_isSameEvent
(
_currentEvent
,
event
));
assert
(
_isSameEvent
(
_currentEvent
!
,
event
));
try
{
try
{
_firstRegisteredCallback
(
_currentEvent
);
_firstRegisteredCallback
!(
_currentEvent
!
);
}
catch
(
exception
,
stack
)
{
}
catch
(
exception
,
stack
)
{
InformationCollector
collector
;
InformationCollector
?
collector
;
assert
(()
{
assert
(()
{
collector
=
()
sync
*
{
collector
=
()
sync
*
{
yield
DiagnosticsProperty
<
PointerSignalEvent
>(
'Event'
,
event
,
style:
DiagnosticsTreeStyle
.
errorProperty
);
yield
DiagnosticsProperty
<
PointerSignalEvent
>(
'Event'
,
event
,
style:
DiagnosticsTreeStyle
.
errorProperty
);
...
...
packages/flutter/lib/src/gestures/recognizer.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'dart:async'
;
import
'dart:collection'
;
import
'dart:collection'
;
...
@@ -67,17 +66,17 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
...
@@ -67,17 +66,17 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
/// by providing the optional [kind] argument. If [kind] is null,
/// by providing the optional [kind] argument. If [kind] is null,
/// the recognizer will accept pointer events from all device kinds.
/// the recognizer will accept pointer events from all device kinds.
/// {@endtemplate}
/// {@endtemplate}
GestureRecognizer
({
this
.
debugOwner
,
PointerDeviceKind
kind
})
:
_kindFilter
=
kind
;
GestureRecognizer
({
this
.
debugOwner
,
PointerDeviceKind
?
kind
})
:
_kindFilter
=
kind
;
/// The recognizer's owner.
/// The recognizer's owner.
///
///
/// This is used in the [toString] serialization to report the object for which
/// This is used in the [toString] serialization to report the object for which
/// this gesture recognizer was created, to aid in debugging.
/// this gesture recognizer was created, to aid in debugging.
final
Object
debugOwner
;
final
Object
?
debugOwner
;
/// The kind of device that's allowed to be recognized. If null, events from
/// The kind of device that's allowed to be recognized. If null, events from
/// all device kinds will be tracked and recognized.
/// all device kinds will be tracked and recognized.
final
PointerDeviceKind
_kindFilter
;
final
PointerDeviceKind
?
_kindFilter
;
/// Holds a mapping between pointer IDs and the kind of devices they are
/// Holds a mapping between pointer IDs and the kind of devices they are
/// coming from.
/// coming from.
...
@@ -141,7 +140,7 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
...
@@ -141,7 +140,7 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
@protected
@protected
PointerDeviceKind
getKindForPointer
(
int
pointer
)
{
PointerDeviceKind
getKindForPointer
(
int
pointer
)
{
assert
(
_pointerToKind
.
containsKey
(
pointer
));
assert
(
_pointerToKind
.
containsKey
(
pointer
));
return
_pointerToKind
[
pointer
];
return
_pointerToKind
[
pointer
]
!
;
}
}
/// Releases any resources used by the object.
/// Releases any resources used by the object.
...
@@ -167,13 +166,13 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
...
@@ -167,13 +166,13 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
/// callback that returns a string describing useful debugging information,
/// callback that returns a string describing useful debugging information,
/// e.g. the arguments passed to the callback.
/// e.g. the arguments passed to the callback.
@protected
@protected
T
invokeCallback
<
T
>(
String
name
,
RecognizerCallback
<
T
>
callback
,
{
String
debugReport
()
})
{
T
?
invokeCallback
<
T
>(
String
name
,
RecognizerCallback
<
T
>
callback
,
{
String
Function
()?
debugReport
})
{
assert
(
callback
!=
null
);
assert
(
callback
!=
null
);
T
result
;
T
?
result
;
try
{
try
{
assert
(()
{
assert
(()
{
if
(
debugPrintRecognizerCallbacksTrace
)
{
if
(
debugPrintRecognizerCallbacksTrace
)
{
final
String
report
=
debugReport
!=
null
?
debugReport
()
:
null
;
final
String
?
report
=
debugReport
!=
null
?
debugReport
()
:
null
;
// The 19 in the line below is the width of the prefix used by
// The 19 in the line below is the width of the prefix used by
// _debugLogDiagnostic in arena.dart.
// _debugLogDiagnostic in arena.dart.
final
String
prefix
=
debugPrintGestureArenaDiagnostics
?
' '
*
19
+
'❙ '
:
''
;
final
String
prefix
=
debugPrintGestureArenaDiagnostics
?
' '
*
19
+
'❙ '
:
''
;
...
@@ -183,7 +182,7 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
...
@@ -183,7 +182,7 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
}());
}());
result
=
callback
();
result
=
callback
();
}
catch
(
exception
,
stack
)
{
}
catch
(
exception
,
stack
)
{
InformationCollector
collector
;
InformationCollector
?
collector
;
assert
(()
{
assert
(()
{
collector
=
()
sync
*
{
collector
=
()
sync
*
{
yield
StringProperty
(
'Handler'
,
name
);
yield
StringProperty
(
'Handler'
,
name
);
...
@@ -222,8 +221,8 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -222,8 +221,8 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
OneSequenceGestureRecognizer
({
OneSequenceGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
final
Map
<
int
,
GestureArenaEntry
>
_entries
=
<
int
,
GestureArenaEntry
>{};
final
Map
<
int
,
GestureArenaEntry
>
_entries
=
<
int
,
GestureArenaEntry
>{};
...
@@ -267,7 +266,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -267,7 +266,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
@protected
@protected
@mustCallSuper
@mustCallSuper
void
resolvePointer
(
int
pointer
,
GestureDisposition
disposition
)
{
void
resolvePointer
(
int
pointer
,
GestureDisposition
disposition
)
{
final
GestureArenaEntry
entry
=
_entries
[
pointer
];
final
GestureArenaEntry
?
entry
=
_entries
[
pointer
];
if
(
entry
!=
null
)
{
if
(
entry
!=
null
)
{
entry
.
resolve
(
disposition
);
entry
.
resolve
(
disposition
);
_entries
.
remove
(
pointer
);
_entries
.
remove
(
pointer
);
...
@@ -278,7 +277,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -278,7 +277,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
void
dispose
()
{
void
dispose
()
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
for
(
final
int
pointer
in
_trackedPointers
)
for
(
final
int
pointer
in
_trackedPointers
)
GestureBinding
.
instance
.
pointerRouter
.
removeRoute
(
pointer
,
handleEvent
);
GestureBinding
.
instance
!
.
pointerRouter
.
removeRoute
(
pointer
,
handleEvent
);
_trackedPointers
.
clear
();
_trackedPointers
.
clear
();
assert
(
_entries
.
isEmpty
);
assert
(
_entries
.
isEmpty
);
super
.
dispose
();
super
.
dispose
();
...
@@ -294,10 +293,10 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -294,10 +293,10 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
/// A recognizer can be assigned to a team only when it is not participating
/// A recognizer can be assigned to a team only when it is not participating
/// in the arena. For example, a common time to assign a recognizer to a team
/// in the arena. For example, a common time to assign a recognizer to a team
/// is shortly after creating the recognizer.
/// is shortly after creating the recognizer.
GestureArenaTeam
get
team
=>
_team
;
GestureArenaTeam
?
get
team
=>
_team
;
GestureArenaTeam
_team
;
GestureArenaTeam
?
_team
;
/// The [team] can only be set once.
/// The [team] can only be set once.
set
team
(
GestureArenaTeam
value
)
{
set
team
(
GestureArenaTeam
?
value
)
{
assert
(
value
!=
null
);
assert
(
value
!=
null
);
assert
(
_entries
.
isEmpty
);
assert
(
_entries
.
isEmpty
);
assert
(
_trackedPointers
.
isEmpty
);
assert
(
_trackedPointers
.
isEmpty
);
...
@@ -307,8 +306,8 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -307,8 +306,8 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
GestureArenaEntry
_addPointerToArena
(
int
pointer
)
{
GestureArenaEntry
_addPointerToArena
(
int
pointer
)
{
if
(
_team
!=
null
)
if
(
_team
!=
null
)
return
_team
.
add
(
pointer
,
this
);
return
_team
!
.
add
(
pointer
,
this
);
return
GestureBinding
.
instance
.
gestureArena
.
add
(
pointer
,
this
);
return
GestureBinding
.
instance
!
.
gestureArena
.
add
(
pointer
,
this
);
}
}
/// Causes events related to the given pointer ID to be routed to this recognizer.
/// Causes events related to the given pointer ID to be routed to this recognizer.
...
@@ -321,8 +320,8 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -321,8 +320,8 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
///
///
/// Use [stopTrackingPointer] to remove the route added by this function.
/// Use [stopTrackingPointer] to remove the route added by this function.
@protected
@protected
void
startTrackingPointer
(
int
pointer
,
[
Matrix4
transform
])
{
void
startTrackingPointer
(
int
pointer
,
[
Matrix4
?
transform
])
{
GestureBinding
.
instance
.
pointerRouter
.
addRoute
(
pointer
,
handleEvent
,
transform
);
GestureBinding
.
instance
!
.
pointerRouter
.
addRoute
(
pointer
,
handleEvent
,
transform
);
_trackedPointers
.
add
(
pointer
);
_trackedPointers
.
add
(
pointer
);
assert
(!
_entries
.
containsValue
(
pointer
));
assert
(!
_entries
.
containsValue
(
pointer
));
_entries
[
pointer
]
=
_addPointerToArena
(
pointer
);
_entries
[
pointer
]
=
_addPointerToArena
(
pointer
);
...
@@ -337,7 +336,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
...
@@ -337,7 +336,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
@protected
@protected
void
stopTrackingPointer
(
int
pointer
)
{
void
stopTrackingPointer
(
int
pointer
)
{
if
(
_trackedPointers
.
contains
(
pointer
))
{
if
(
_trackedPointers
.
contains
(
pointer
))
{
GestureBinding
.
instance
.
pointerRouter
.
removeRoute
(
pointer
,
handleEvent
);
GestureBinding
.
instance
!
.
pointerRouter
.
removeRoute
(
pointer
,
handleEvent
);
_trackedPointers
.
remove
(
pointer
);
_trackedPointers
.
remove
(
pointer
);
if
(
_trackedPointers
.
isEmpty
)
if
(
_trackedPointers
.
isEmpty
)
didStopTrackingLastPointer
(
pointer
);
didStopTrackingLastPointer
(
pointer
);
...
@@ -391,8 +390,8 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -391,8 +390,8 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
this
.
deadline
,
this
.
deadline
,
this
.
preAcceptSlopTolerance
=
kTouchSlop
,
this
.
preAcceptSlopTolerance
=
kTouchSlop
,
this
.
postAcceptSlopTolerance
=
kTouchSlop
,
this
.
postAcceptSlopTolerance
=
kTouchSlop
,
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
assert
(
})
:
assert
(
preAcceptSlopTolerance
==
null
||
preAcceptSlopTolerance
>=
0
,
preAcceptSlopTolerance
==
null
||
preAcceptSlopTolerance
>=
0
,
'The preAcceptSlopTolerance must be positive or null'
,
'The preAcceptSlopTolerance must be positive or null'
,
...
@@ -408,7 +407,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -408,7 +407,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
///
///
/// The [didExceedDeadline] will not be called if the primary pointer is
/// The [didExceedDeadline] will not be called if the primary pointer is
/// accepted, rejected, or all pointers are up or canceled before [deadline].
/// accepted, rejected, or all pointers are up or canceled before [deadline].
final
Duration
deadline
;
final
Duration
?
deadline
;
/// The maximum distance in logical pixels the gesture is allowed to drift
/// The maximum distance in logical pixels the gesture is allowed to drift
/// from the initial touch down position before the gesture is accepted.
/// from the initial touch down position before the gesture is accepted.
...
@@ -417,7 +416,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -417,7 +416,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
///
///
/// Can be null to indicate that the gesture can drift for any distance.
/// Can be null to indicate that the gesture can drift for any distance.
/// Defaults to 18 logical pixels.
/// Defaults to 18 logical pixels.
final
double
preAcceptSlopTolerance
;
final
double
?
preAcceptSlopTolerance
;
/// The maximum distance in logical pixels the gesture is allowed to drift
/// The maximum distance in logical pixels the gesture is allowed to drift
/// after the gesture has been accepted.
/// after the gesture has been accepted.
...
@@ -427,7 +426,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -427,7 +426,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
///
///
/// Can be null to indicate that the gesture can drift for any distance.
/// Can be null to indicate that the gesture can drift for any distance.
/// Defaults to 18 logical pixels.
/// Defaults to 18 logical pixels.
final
double
postAcceptSlopTolerance
;
final
double
?
postAcceptSlopTolerance
;
/// The current state of the recognizer.
/// The current state of the recognizer.
///
///
...
@@ -435,15 +434,15 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -435,15 +434,15 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
GestureRecognizerState
state
=
GestureRecognizerState
.
ready
;
GestureRecognizerState
state
=
GestureRecognizerState
.
ready
;
/// The ID of the primary pointer this recognizer is tracking.
/// The ID of the primary pointer this recognizer is tracking.
int
primaryPointer
;
int
?
primaryPointer
;
/// The location at which the primary pointer contacted the screen.
/// The location at which the primary pointer contacted the screen.
OffsetPair
initialPosition
;
OffsetPair
?
initialPosition
;
// Whether this pointer is accepted by winning the arena or as defined by
// Whether this pointer is accepted by winning the arena or as defined by
// a subclass calling acceptGesture.
// a subclass calling acceptGesture.
bool
_gestureAccepted
=
false
;
bool
_gestureAccepted
=
false
;
Timer
_timer
;
Timer
?
_timer
;
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
...
@@ -453,7 +452,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -453,7 +452,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
primaryPointer
=
event
.
pointer
;
primaryPointer
=
event
.
pointer
;
initialPosition
=
OffsetPair
(
local:
event
.
localPosition
,
global:
event
.
position
);
initialPosition
=
OffsetPair
(
local:
event
.
localPosition
,
global:
event
.
position
);
if
(
deadline
!=
null
)
if
(
deadline
!=
null
)
_timer
=
Timer
(
deadline
,
()
=>
didExceedDeadlineWithEvent
(
event
));
_timer
=
Timer
(
deadline
!
,
()
=>
didExceedDeadlineWithEvent
(
event
));
}
}
}
}
...
@@ -464,15 +463,15 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -464,15 +463,15 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
final
bool
isPreAcceptSlopPastTolerance
=
final
bool
isPreAcceptSlopPastTolerance
=
!
_gestureAccepted
&&
!
_gestureAccepted
&&
preAcceptSlopTolerance
!=
null
&&
preAcceptSlopTolerance
!=
null
&&
_getGlobalDistance
(
event
)
>
preAcceptSlopTolerance
;
_getGlobalDistance
(
event
)
>
preAcceptSlopTolerance
!
;
final
bool
isPostAcceptSlopPastTolerance
=
final
bool
isPostAcceptSlopPastTolerance
=
_gestureAccepted
&&
_gestureAccepted
&&
postAcceptSlopTolerance
!=
null
&&
postAcceptSlopTolerance
!=
null
&&
_getGlobalDistance
(
event
)
>
postAcceptSlopTolerance
;
_getGlobalDistance
(
event
)
>
postAcceptSlopTolerance
!
;
if
(
event
is
PointerMoveEvent
&&
(
isPreAcceptSlopPastTolerance
||
isPostAcceptSlopPastTolerance
))
{
if
(
event
is
PointerMoveEvent
&&
(
isPreAcceptSlopPastTolerance
||
isPostAcceptSlopPastTolerance
))
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
stopTrackingPointer
(
primaryPointer
);
stopTrackingPointer
(
primaryPointer
!
);
}
else
{
}
else
{
handlePrimaryPointer
(
event
);
handlePrimaryPointer
(
event
);
}
}
...
@@ -534,13 +533,13 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -534,13 +533,13 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
void
_stopTimer
()
{
void
_stopTimer
()
{
if
(
_timer
!=
null
)
{
if
(
_timer
!=
null
)
{
_timer
.
cancel
();
_timer
!
.
cancel
();
_timer
=
null
;
_timer
=
null
;
}
}
}
}
double
_getGlobalDistance
(
PointerEvent
event
)
{
double
_getGlobalDistance
(
PointerEvent
event
)
{
final
Offset
offset
=
event
.
position
-
initialPosition
.
global
;
final
Offset
offset
=
event
.
position
-
initialPosition
!
.
global
;
return
offset
.
distance
;
return
offset
.
distance
;
}
}
...
@@ -559,8 +558,8 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
...
@@ -559,8 +558,8 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
class
OffsetPair
{
class
OffsetPair
{
/// Creates a [OffsetPair] combining a [local] and [global] [Offset].
/// Creates a [OffsetPair] combining a [local] and [global] [Offset].
const
OffsetPair
({
const
OffsetPair
({
@
required
this
.
local
,
required
this
.
local
,
@
required
this
.
global
,
required
this
.
global
,
});
});
/// Creates a [OffsetPair] from [PointerEvent.localPosition] and
/// Creates a [OffsetPair] from [PointerEvent.localPosition] and
...
...
packages/flutter/lib/src/gestures/scale.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:math'
as
math
;
import
'dart:math'
as
math
;
...
@@ -38,7 +37,7 @@ class ScaleStartDetails {
...
@@ -38,7 +37,7 @@ class ScaleStartDetails {
/// Creates details for [GestureScaleStartCallback].
/// Creates details for [GestureScaleStartCallback].
///
///
/// The [focalPoint] argument must not be null.
/// The [focalPoint] argument must not be null.
ScaleStartDetails
({
this
.
focalPoint
=
Offset
.
zero
,
Offset
localFocalPoint
,
})
ScaleStartDetails
({
this
.
focalPoint
=
Offset
.
zero
,
Offset
?
localFocalPoint
,
})
:
assert
(
focalPoint
!=
null
),
localFocalPoint
=
localFocalPoint
??
focalPoint
;
:
assert
(
focalPoint
!=
null
),
localFocalPoint
=
localFocalPoint
??
focalPoint
;
/// The initial focal point of the pointers in contact with the screen.
/// The initial focal point of the pointers in contact with the screen.
...
@@ -75,7 +74,7 @@ class ScaleUpdateDetails {
...
@@ -75,7 +74,7 @@ class ScaleUpdateDetails {
/// argument must be greater than or equal to zero.
/// argument must be greater than or equal to zero.
ScaleUpdateDetails
({
ScaleUpdateDetails
({
this
.
focalPoint
=
Offset
.
zero
,
this
.
focalPoint
=
Offset
.
zero
,
Offset
localFocalPoint
,
Offset
?
localFocalPoint
,
this
.
scale
=
1.0
,
this
.
scale
=
1.0
,
this
.
horizontalScale
=
1.0
,
this
.
horizontalScale
=
1.0
,
this
.
verticalScale
=
1.0
,
this
.
verticalScale
=
1.0
,
...
@@ -225,37 +224,37 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -225,37 +224,37 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
///
///
/// {@macro flutter.gestures.gestureRecognizer.kind}
/// {@macro flutter.gestures.gestureRecognizer.kind}
ScaleGestureRecognizer
({
ScaleGestureRecognizer
({
Object
debugOwner
,
Object
?
debugOwner
,
PointerDeviceKind
kind
,
PointerDeviceKind
?
kind
,
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
})
:
super
(
debugOwner:
debugOwner
,
kind:
kind
);
/// The pointers in contact with the screen have established a focal point and
/// The pointers in contact with the screen have established a focal point and
/// initial scale of 1.0.
/// initial scale of 1.0.
GestureScaleStartCallback
onStart
;
GestureScaleStartCallback
?
onStart
;
/// The pointers in contact with the screen have indicated a new focal point
/// The pointers in contact with the screen have indicated a new focal point
/// and/or scale.
/// and/or scale.
GestureScaleUpdateCallback
onUpdate
;
GestureScaleUpdateCallback
?
onUpdate
;
/// The pointers are no longer in contact with the screen.
/// The pointers are no longer in contact with the screen.
GestureScaleEndCallback
onEnd
;
GestureScaleEndCallback
?
onEnd
;
_ScaleState
_state
=
_ScaleState
.
ready
;
_ScaleState
_state
=
_ScaleState
.
ready
;
Matrix4
_lastTransform
;
Matrix4
?
_lastTransform
;
Offset
_initialFocalPoint
;
late
Offset
_initialFocalPoint
;
Offset
_currentFocalPoint
;
late
Offset
_currentFocalPoint
;
double
_initialSpan
;
late
double
_initialSpan
;
double
_currentSpan
;
late
double
_currentSpan
;
double
_initialHorizontalSpan
;
late
double
_initialHorizontalSpan
;
double
_currentHorizontalSpan
;
late
double
_currentHorizontalSpan
;
double
_initialVerticalSpan
;
late
double
_initialVerticalSpan
;
double
_currentVerticalSpan
;
late
double
_currentVerticalSpan
;
_LineBetweenPointers
_initialLine
;
_LineBetweenPointers
?
_initialLine
;
_LineBetweenPointers
_currentLine
;
_LineBetweenPointers
?
_currentLine
;
Map
<
int
,
Offset
>
_pointerLocations
;
late
Map
<
int
,
Offset
>
_pointerLocations
;
List
<
int
>
_pointerQueue
;
// A queue to sort pointers in order of entrance
late
List
<
int
>
_pointerQueue
;
// A queue to sort pointers in order of entrance
final
Map
<
int
,
VelocityTracker
>
_velocityTrackers
=
<
int
,
VelocityTracker
>{};
final
Map
<
int
,
VelocityTracker
>
_velocityTrackers
=
<
int
,
VelocityTracker
>{};
double
get
_scaleFactor
=>
_initialSpan
>
0.0
?
_currentSpan
/
_initialSpan
:
1.0
;
double
get
_scaleFactor
=>
_initialSpan
>
0.0
?
_currentSpan
/
_initialSpan
:
1.0
;
...
@@ -268,15 +267,15 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -268,15 +267,15 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
_initialLine
==
null
||
_currentLine
==
null
)
{
if
(
_initialLine
==
null
||
_currentLine
==
null
)
{
return
0.0
;
return
0.0
;
}
}
final
double
fx
=
_initialLine
.
pointerStartLocation
.
dx
;
final
double
fx
=
_initialLine
!
.
pointerStartLocation
.
dx
;
final
double
fy
=
_initialLine
.
pointerStartLocation
.
dy
;
final
double
fy
=
_initialLine
!
.
pointerStartLocation
.
dy
;
final
double
sx
=
_initialLine
.
pointerEndLocation
.
dx
;
final
double
sx
=
_initialLine
!
.
pointerEndLocation
.
dx
;
final
double
sy
=
_initialLine
.
pointerEndLocation
.
dy
;
final
double
sy
=
_initialLine
!
.
pointerEndLocation
.
dy
;
final
double
nfx
=
_currentLine
.
pointerStartLocation
.
dx
;
final
double
nfx
=
_currentLine
!
.
pointerStartLocation
.
dx
;
final
double
nfy
=
_currentLine
.
pointerStartLocation
.
dy
;
final
double
nfy
=
_currentLine
!
.
pointerStartLocation
.
dy
;
final
double
nsx
=
_currentLine
.
pointerEndLocation
.
dx
;
final
double
nsx
=
_currentLine
!
.
pointerEndLocation
.
dx
;
final
double
nsy
=
_currentLine
.
pointerEndLocation
.
dy
;
final
double
nsy
=
_currentLine
!
.
pointerEndLocation
.
dy
;
final
double
angle1
=
math
.
atan2
(
fy
-
sy
,
fx
-
sx
);
final
double
angle1
=
math
.
atan2
(
fy
-
sy
,
fx
-
sx
);
final
double
angle2
=
math
.
atan2
(
nfy
-
nsy
,
nfx
-
nsx
);
final
double
angle2
=
math
.
atan2
(
nfy
-
nsy
,
nfx
-
nsx
);
...
@@ -307,8 +306,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -307,8 +306,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
bool
didChangeConfiguration
=
false
;
bool
didChangeConfiguration
=
false
;
bool
shouldStartIfAccepted
=
false
;
bool
shouldStartIfAccepted
=
false
;
if
(
event
is
PointerMoveEvent
)
{
if
(
event
is
PointerMoveEvent
)
{
final
VelocityTracker
tracker
=
_velocityTrackers
[
event
.
pointer
];
final
VelocityTracker
tracker
=
_velocityTrackers
[
event
.
pointer
]!;
assert
(
tracker
!=
null
);
if
(!
event
.
synthesized
)
if
(!
event
.
synthesized
)
tracker
.
addPosition
(
event
.
timeStamp
,
event
.
position
);
tracker
.
addPosition
(
event
.
timeStamp
,
event
.
position
);
_pointerLocations
[
event
.
pointer
]
=
event
.
position
;
_pointerLocations
[
event
.
pointer
]
=
event
.
position
;
...
@@ -341,7 +339,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -341,7 +339,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
// Compute the focal point
// Compute the focal point
Offset
focalPoint
=
Offset
.
zero
;
Offset
focalPoint
=
Offset
.
zero
;
for
(
final
int
pointer
in
_pointerLocations
.
keys
)
for
(
final
int
pointer
in
_pointerLocations
.
keys
)
focalPoint
+=
_pointerLocations
[
pointer
];
focalPoint
+=
_pointerLocations
[
pointer
]
!
;
_currentFocalPoint
=
count
>
0
?
focalPoint
/
count
.
toDouble
()
:
Offset
.
zero
;
_currentFocalPoint
=
count
>
0
?
focalPoint
/
count
.
toDouble
()
:
Offset
.
zero
;
// Span is the average deviation from focal point. Horizontal and vertical
// Span is the average deviation from focal point. Horizontal and vertical
...
@@ -351,9 +349,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -351,9 +349,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
double
totalHorizontalDeviation
=
0.0
;
double
totalHorizontalDeviation
=
0.0
;
double
totalVerticalDeviation
=
0.0
;
double
totalVerticalDeviation
=
0.0
;
for
(
final
int
pointer
in
_pointerLocations
.
keys
)
{
for
(
final
int
pointer
in
_pointerLocations
.
keys
)
{
totalDeviation
+=
(
_currentFocalPoint
-
_pointerLocations
[
pointer
]).
distance
;
totalDeviation
+=
(
_currentFocalPoint
-
_pointerLocations
[
pointer
]
!
).
distance
;
totalHorizontalDeviation
+=
(
_currentFocalPoint
.
dx
-
_pointerLocations
[
pointer
].
dx
).
abs
();
totalHorizontalDeviation
+=
(
_currentFocalPoint
.
dx
-
_pointerLocations
[
pointer
]
!
.
dx
).
abs
();
totalVerticalDeviation
+=
(
_currentFocalPoint
.
dy
-
_pointerLocations
[
pointer
].
dy
).
abs
();
totalVerticalDeviation
+=
(
_currentFocalPoint
.
dy
-
_pointerLocations
[
pointer
]
!
.
dy
).
abs
();
}
}
_currentSpan
=
count
>
0
?
totalDeviation
/
count
:
0.0
;
_currentSpan
=
count
>
0
?
totalDeviation
/
count
:
0.0
;
_currentHorizontalSpan
=
count
>
0
?
totalHorizontalDeviation
/
count
:
0.0
;
_currentHorizontalSpan
=
count
>
0
?
totalHorizontalDeviation
/
count
:
0.0
;
...
@@ -369,22 +367,22 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -369,22 +367,22 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
count
<
2
)
{
if
(
count
<
2
)
{
_initialLine
=
_currentLine
;
_initialLine
=
_currentLine
;
}
else
if
(
_initialLine
!=
null
&&
}
else
if
(
_initialLine
!=
null
&&
_initialLine
.
pointerStartId
==
_pointerQueue
[
0
]
&&
_initialLine
!
.
pointerStartId
==
_pointerQueue
[
0
]
&&
_initialLine
.
pointerEndId
==
_pointerQueue
[
1
])
{
_initialLine
!
.
pointerEndId
==
_pointerQueue
[
1
])
{
/// Rotation updated, set the [_currentLine]
/// Rotation updated, set the [_currentLine]
_currentLine
=
_LineBetweenPointers
(
_currentLine
=
_LineBetweenPointers
(
pointerStartId:
_pointerQueue
[
0
],
pointerStartId:
_pointerQueue
[
0
],
pointerStartLocation:
_pointerLocations
[
_pointerQueue
[
0
]],
pointerStartLocation:
_pointerLocations
[
_pointerQueue
[
0
]]
!
,
pointerEndId:
_pointerQueue
[
1
],
pointerEndId:
_pointerQueue
[
1
],
pointerEndLocation:
_pointerLocations
[
_pointerQueue
[
1
]],
pointerEndLocation:
_pointerLocations
[
_pointerQueue
[
1
]]
!
,
);
);
}
else
{
}
else
{
/// A new rotation process is on the way, set the [_initialLine]
/// A new rotation process is on the way, set the [_initialLine]
_initialLine
=
_LineBetweenPointers
(
_initialLine
=
_LineBetweenPointers
(
pointerStartId:
_pointerQueue
[
0
],
pointerStartId:
_pointerQueue
[
0
],
pointerStartLocation:
_pointerLocations
[
_pointerQueue
[
0
]],
pointerStartLocation:
_pointerLocations
[
_pointerQueue
[
0
]]
!
,
pointerEndId:
_pointerQueue
[
1
],
pointerEndId:
_pointerQueue
[
1
],
pointerEndLocation:
_pointerLocations
[
_pointerQueue
[
1
]],
pointerEndLocation:
_pointerLocations
[
_pointerQueue
[
1
]]
!
,
);
);
_currentLine
=
null
;
_currentLine
=
null
;
}
}
...
@@ -398,17 +396,16 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -398,17 +396,16 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
_initialVerticalSpan
=
_currentVerticalSpan
;
_initialVerticalSpan
=
_currentVerticalSpan
;
if
(
_state
==
_ScaleState
.
started
)
{
if
(
_state
==
_ScaleState
.
started
)
{
if
(
onEnd
!=
null
)
{
if
(
onEnd
!=
null
)
{
final
VelocityTracker
tracker
=
_velocityTrackers
[
pointer
];
final
VelocityTracker
tracker
=
_velocityTrackers
[
pointer
]!;
assert
(
tracker
!=
null
);
Velocity
velocity
=
tracker
.
getVelocity
();
Velocity
velocity
=
tracker
.
getVelocity
();
if
(
_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
=
Velocity
(
pixelsPerSecond:
(
pixelsPerSecond
/
pixelsPerSecond
.
distance
)
*
kMaxFlingVelocity
);
velocity
=
Velocity
(
pixelsPerSecond:
(
pixelsPerSecond
/
pixelsPerSecond
.
distance
)
*
kMaxFlingVelocity
);
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
(
ScaleEndDetails
(
velocity:
velocity
)));
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
!
(
ScaleEndDetails
(
velocity:
velocity
)));
}
else
{
}
else
{
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
(
ScaleEndDetails
(
velocity:
Velocity
.
zero
)));
invokeCallback
<
void
>(
'onEnd'
,
()
=>
onEnd
!
(
ScaleEndDetails
(
velocity:
Velocity
.
zero
)));
}
}
}
}
_state
=
_ScaleState
.
accepted
;
_state
=
_ScaleState
.
accepted
;
...
@@ -437,7 +434,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -437,7 +434,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if
(
_state
==
_ScaleState
.
started
&&
onUpdate
!=
null
)
if
(
_state
==
_ScaleState
.
started
&&
onUpdate
!=
null
)
invokeCallback
<
void
>(
'onUpdate'
,
()
{
invokeCallback
<
void
>(
'onUpdate'
,
()
{
onUpdate
(
ScaleUpdateDetails
(
onUpdate
!
(
ScaleUpdateDetails
(
scale:
_scaleFactor
,
scale:
_scaleFactor
,
horizontalScale:
_horizontalScaleFactor
,
horizontalScale:
_horizontalScaleFactor
,
verticalScale:
_verticalScaleFactor
,
verticalScale:
_verticalScaleFactor
,
...
@@ -452,7 +449,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
...
@@ -452,7 +449,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
assert
(
_state
==
_ScaleState
.
started
);
assert
(
_state
==
_ScaleState
.
started
);
if
(
onStart
!=
null
)
if
(
onStart
!=
null
)
invokeCallback
<
void
>(
'onStart'
,
()
{
invokeCallback
<
void
>(
'onStart'
,
()
{
onStart
(
ScaleStartDetails
(
onStart
!
(
ScaleStartDetails
(
focalPoint:
_currentFocalPoint
,
focalPoint:
_currentFocalPoint
,
localFocalPoint:
PointerEvent
.
transformPosition
(
_lastTransform
,
_currentFocalPoint
),
localFocalPoint:
PointerEvent
.
transformPosition
(
_lastTransform
,
_currentFocalPoint
),
));
));
...
...
packages/flutter/lib/src/gestures/tap.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:vector_math/vector_math_64.dart'
show
Matrix4
;
import
'package:vector_math/vector_math_64.dart'
show
Matrix4
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
...
@@ -24,7 +23,7 @@ class TapDownDetails {
...
@@ -24,7 +23,7 @@ class TapDownDetails {
/// The [globalPosition] argument must not be null.
/// The [globalPosition] argument must not be null.
TapDownDetails
({
TapDownDetails
({
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
this
.
kind
,
this
.
kind
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -33,7 +32,7 @@ class TapDownDetails {
...
@@ -33,7 +32,7 @@ class TapDownDetails {
final
Offset
globalPosition
;
final
Offset
globalPosition
;
/// The kind of the device that initiated the event.
/// The kind of the device that initiated the event.
final
PointerDeviceKind
kind
;
final
PointerDeviceKind
?
kind
;
/// The local position at which the pointer contacted the screen.
/// The local position at which the pointer contacted the screen.
final
Offset
localPosition
;
final
Offset
localPosition
;
...
@@ -61,7 +60,7 @@ class TapUpDetails {
...
@@ -61,7 +60,7 @@ class TapUpDetails {
/// The [globalPosition] argument must not be null.
/// The [globalPosition] argument must not be null.
TapUpDetails
({
TapUpDetails
({
this
.
globalPosition
=
Offset
.
zero
,
this
.
globalPosition
=
Offset
.
zero
,
Offset
localPosition
,
Offset
?
localPosition
,
})
:
assert
(
globalPosition
!=
null
),
})
:
assert
(
globalPosition
!=
null
),
localPosition
=
localPosition
??
globalPosition
;
localPosition
=
localPosition
??
globalPosition
;
...
@@ -133,14 +132,14 @@ typedef GestureTapCancelCallback = void Function();
...
@@ -133,14 +132,14 @@ typedef GestureTapCancelCallback = void Function();
/// any buttons.
/// any buttons.
abstract
class
BaseTapGestureRecognizer
extends
PrimaryPointerGestureRecognizer
{
abstract
class
BaseTapGestureRecognizer
extends
PrimaryPointerGestureRecognizer
{
/// Creates a tap gesture recognizer.
/// Creates a tap gesture recognizer.
BaseTapGestureRecognizer
({
Object
debugOwner
})
BaseTapGestureRecognizer
({
Object
?
debugOwner
})
:
super
(
deadline:
kPressTimeout
,
debugOwner:
debugOwner
);
:
super
(
deadline:
kPressTimeout
,
debugOwner:
debugOwner
);
bool
_sentTapDown
=
false
;
bool
_sentTapDown
=
false
;
bool
_wonArenaForPrimaryPointer
=
false
;
bool
_wonArenaForPrimaryPointer
=
false
;
PointerDownEvent
_down
;
PointerDownEvent
?
_down
;
PointerUpEvent
_up
;
PointerUpEvent
?
_up
;
/// A pointer has contacted the screen, which might be the start of a tap.
/// A pointer has contacted the screen, which might be the start of a tap.
///
///
...
@@ -153,7 +152,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -153,7 +152,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
/// If this recognizer doesn't win the arena, [handleTapCancel] is called next.
/// If this recognizer doesn't win the arena, [handleTapCancel] is called next.
/// Otherwise, [handleTapUp] is called next.
/// Otherwise, [handleTapUp] is called next.
@protected
@protected
void
handleTapDown
({
PointerDownEvent
down
});
void
handleTapDown
({
required
PointerDownEvent
down
});
/// A pointer has stopped contacting the screen, which is recognized as a tap.
/// A pointer has stopped contacting the screen, which is recognized as a tap.
///
///
...
@@ -166,7 +165,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -166,7 +165,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
/// If this recognizer doesn't win the arena, [handleTapCancel] is called
/// If this recognizer doesn't win the arena, [handleTapCancel] is called
/// instead.
/// instead.
@protected
@protected
void
handleTapUp
({
PointerDownEvent
down
,
PointerUpEvent
up
});
void
handleTapUp
({
required
PointerDownEvent
down
,
required
PointerUpEvent
up
});
/// A pointer that previously triggered [handleTapDown] will not end up
/// A pointer that previously triggered [handleTapDown] will not end up
/// causing a tap.
/// causing a tap.
...
@@ -182,7 +181,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -182,7 +181,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
///
///
/// If this recognizer wins the arena, [handleTapUp] is called instead.
/// If this recognizer wins the arena, [handleTapUp] is called instead.
@protected
@protected
void
handleTapCancel
({
PointerDownEvent
down
,
PointerCancelEvent
cancel
,
String
reason
});
void
handleTapCancel
({
required
PointerDownEvent
down
,
PointerCancelEvent
?
cancel
,
required
String
reason
});
@override
@override
void
addAllowedPointer
(
PointerDownEvent
event
)
{
void
addAllowedPointer
(
PointerDownEvent
event
)
{
...
@@ -205,7 +204,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -205,7 +204,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
@override
@override
@protected
@protected
void
startTrackingPointer
(
int
pointer
,
[
Matrix4
transform
])
{
void
startTrackingPointer
(
int
pointer
,
[
Matrix4
?
transform
])
{
// The recognizer should never track any pointers when `_down` is null,
// The recognizer should never track any pointers when `_down` is null,
// because calling `_checkDown` in this state will throw exception.
// because calling `_checkDown` in this state will throw exception.
assert
(
_down
!=
null
);
assert
(
_down
!=
null
);
...
@@ -223,9 +222,9 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -223,9 +222,9 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
_checkCancel
(
event
,
''
);
_checkCancel
(
event
,
''
);
}
}
_reset
();
_reset
();
}
else
if
(
event
.
buttons
!=
_down
.
buttons
)
{
}
else
if
(
event
.
buttons
!=
_down
!
.
buttons
)
{
resolve
(
GestureDisposition
.
rejected
);
resolve
(
GestureDisposition
.
rejected
);
stopTrackingPointer
(
primaryPointer
);
stopTrackingPointer
(
primaryPointer
!
);
}
}
}
}
...
@@ -273,7 +272,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -273,7 +272,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
if
(
_sentTapDown
)
{
if
(
_sentTapDown
)
{
return
;
return
;
}
}
handleTapDown
(
down:
_down
);
handleTapDown
(
down:
_down
!
);
_sentTapDown
=
true
;
_sentTapDown
=
true
;
}
}
...
@@ -281,12 +280,12 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -281,12 +280,12 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
if
(!
_wonArenaForPrimaryPointer
||
_up
==
null
)
{
if
(!
_wonArenaForPrimaryPointer
||
_up
==
null
)
{
return
;
return
;
}
}
handleTapUp
(
down:
_down
,
up:
_up
);
handleTapUp
(
down:
_down
!,
up:
_up
!
);
_reset
();
_reset
();
}
}
void
_checkCancel
(
PointerCancelEvent
event
,
String
note
)
{
void
_checkCancel
(
PointerCancelEvent
?
event
,
String
note
)
{
handleTapCancel
(
down:
_down
,
cancel:
event
,
reason:
note
);
handleTapCancel
(
down:
_down
!
,
cancel:
event
,
reason:
note
);
}
}
void
_reset
()
{
void
_reset
()
{
...
@@ -332,7 +331,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
...
@@ -332,7 +331,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
/// * [MultiTapGestureRecognizer]
/// * [MultiTapGestureRecognizer]
class
TapGestureRecognizer
extends
BaseTapGestureRecognizer
{
class
TapGestureRecognizer
extends
BaseTapGestureRecognizer
{
/// Creates a tap gesture recognizer.
/// Creates a tap gesture recognizer.
TapGestureRecognizer
({
Object
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
TapGestureRecognizer
({
Object
?
debugOwner
})
:
super
(
debugOwner:
debugOwner
);
/// A pointer has contacted the screen at a particular location with a primary
/// A pointer has contacted the screen at a particular location with a primary
/// button, which might be the start of a tap.
/// button, which might be the start of a tap.
...
@@ -349,7 +348,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -349,7 +348,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [onSecondaryTapDown], a similar callback but for a secondary button.
/// * [onSecondaryTapDown], a similar callback but for a secondary button.
/// * [TapDownDetails], which is passed as an argument to this callback.
/// * [TapDownDetails], which is passed as an argument to this callback.
/// * [GestureDetector.onTapDown], which exposes this callback.
/// * [GestureDetector.onTapDown], which exposes this callback.
GestureTapDownCallback
onTapDown
;
GestureTapDownCallback
?
onTapDown
;
/// A pointer has stopped contacting the screen at a particular location,
/// A pointer has stopped contacting the screen at a particular location,
/// which is recognized as a tap of a primary button.
/// which is recognized as a tap of a primary button.
...
@@ -365,7 +364,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -365,7 +364,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [onSecondaryTapUp], a similar callback but for a secondary button.
/// * [onSecondaryTapUp], a similar callback but for a secondary button.
/// * [TapUpDetails], which is passed as an argument to this callback.
/// * [TapUpDetails], which is passed as an argument to this callback.
/// * [GestureDetector.onTapUp], which exposes this callback.
/// * [GestureDetector.onTapUp], which exposes this callback.
GestureTapUpCallback
onTapUp
;
GestureTapUpCallback
?
onTapUp
;
/// A pointer has stopped contacting the screen, which is recognized as a tap
/// A pointer has stopped contacting the screen, which is recognized as a tap
/// of a primary button.
/// of a primary button.
...
@@ -380,7 +379,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -380,7 +379,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [onTapUp], which has the same timing but with details.
/// * [onTapUp], which has the same timing but with details.
/// * [GestureDetector.onTap], which exposes this callback.
/// * [GestureDetector.onTap], which exposes this callback.
GestureTapCallback
onTap
;
GestureTapCallback
?
onTap
;
/// A pointer that previously triggered [onTapDown] will not end up causing
/// A pointer that previously triggered [onTapDown] will not end up causing
/// a tap.
/// a tap.
...
@@ -396,7 +395,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -396,7 +395,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [kPrimaryButton], the button this callback responds to.
/// * [kPrimaryButton], the button this callback responds to.
/// * [onSecondaryTapCancel], a similar callback but for a secondary button.
/// * [onSecondaryTapCancel], a similar callback but for a secondary button.
/// * [GestureDetector.onTapCancel], which exposes this callback.
/// * [GestureDetector.onTapCancel], which exposes this callback.
GestureTapCancelCallback
onTapCancel
;
GestureTapCancelCallback
?
onTapCancel
;
/// A pointer has stopped contacting the screen, which is recognized as a tap
/// A pointer has stopped contacting the screen, which is recognized as a tap
/// of a secondary button.
/// of a secondary button.
...
@@ -412,7 +411,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -412,7 +411,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [kSecondaryButton], the button this callback responds to.
/// * [kSecondaryButton], the button this callback responds to.
/// * [onSecondaryTapUp], which has the same timing but with details.
/// * [onSecondaryTapUp], which has the same timing but with details.
/// * [GestureDetector.onSecondaryTap], which exposes this callback.
/// * [GestureDetector.onSecondaryTap], which exposes this callback.
GestureTapCallback
onSecondaryTap
;
GestureTapCallback
?
onSecondaryTap
;
/// A pointer has contacted the screen at a particular location with a
/// A pointer has contacted the screen at a particular location with a
/// secondary button, which might be the start of a secondary tap.
/// secondary button, which might be the start of a secondary tap.
...
@@ -429,7 +428,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -429,7 +428,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [onTapDown], a similar callback but for a primary button.
/// * [onTapDown], a similar callback but for a primary button.
/// * [TapDownDetails], which is passed as an argument to this callback.
/// * [TapDownDetails], which is passed as an argument to this callback.
/// * [GestureDetector.onSecondaryTapDown], which exposes this callback.
/// * [GestureDetector.onSecondaryTapDown], which exposes this callback.
GestureTapDownCallback
onSecondaryTapDown
;
GestureTapDownCallback
?
onSecondaryTapDown
;
/// A pointer has stopped contacting the screen at a particular location,
/// A pointer has stopped contacting the screen at a particular location,
/// which is recognized as a tap of a secondary button.
/// which is recognized as a tap of a secondary button.
...
@@ -448,7 +447,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -448,7 +447,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [onTapUp], a similar callback but for a primary button.
/// * [onTapUp], a similar callback but for a primary button.
/// * [TapUpDetails], which is passed as an argument to this callback.
/// * [TapUpDetails], which is passed as an argument to this callback.
/// * [GestureDetector.onSecondaryTapUp], which exposes this callback.
/// * [GestureDetector.onSecondaryTapUp], which exposes this callback.
GestureTapUpCallback
onSecondaryTapUp
;
GestureTapUpCallback
?
onSecondaryTapUp
;
/// A pointer that previously triggered [onSecondaryTapDown] will not end up
/// A pointer that previously triggered [onSecondaryTapDown] will not end up
/// causing a tap.
/// causing a tap.
...
@@ -463,7 +462,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -463,7 +462,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [kSecondaryButton], the button this callback responds to.
/// * [kSecondaryButton], the button this callback responds to.
/// * [onTapCancel], a similar callback but for a primary button.
/// * [onTapCancel], a similar callback but for a primary button.
/// * [GestureDetector.onTapCancel], which exposes this callback.
/// * [GestureDetector.onTapCancel], which exposes this callback.
GestureTapCancelCallback
onSecondaryTapCancel
;
GestureTapCancelCallback
?
onSecondaryTapCancel
;
@override
@override
bool
isPointerAllowed
(
PointerDownEvent
event
)
{
bool
isPointerAllowed
(
PointerDownEvent
event
)
{
...
@@ -490,7 +489,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -490,7 +489,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
@protected
@protected
@override
@override
void
handleTapDown
({
PointerDownEvent
down
})
{
void
handleTapDown
({
required
PointerDownEvent
down
})
{
final
TapDownDetails
details
=
TapDownDetails
(
final
TapDownDetails
details
=
TapDownDetails
(
globalPosition:
down
.
position
,
globalPosition:
down
.
position
,
localPosition:
down
.
localPosition
,
localPosition:
down
.
localPosition
,
...
@@ -499,11 +498,11 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -499,11 +498,11 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
switch
(
down
.
buttons
)
{
switch
(
down
.
buttons
)
{
case
kPrimaryButton:
case
kPrimaryButton:
if
(
onTapDown
!=
null
)
if
(
onTapDown
!=
null
)
invokeCallback
<
void
>(
'onTapDown'
,
()
=>
onTapDown
(
details
));
invokeCallback
<
void
>(
'onTapDown'
,
()
=>
onTapDown
!
(
details
));
break
;
break
;
case
kSecondaryButton:
case
kSecondaryButton:
if
(
onSecondaryTapDown
!=
null
)
if
(
onSecondaryTapDown
!=
null
)
invokeCallback
<
void
>(
'onSecondaryTapDown'
,
()
=>
onSecondaryTapDown
(
details
));
invokeCallback
<
void
>(
'onSecondaryTapDown'
,
()
=>
onSecondaryTapDown
!
(
details
));
break
;
break
;
default
:
default
:
}
}
...
@@ -511,7 +510,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -511,7 +510,7 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
@protected
@protected
@override
@override
void
handleTapUp
({
PointerDownEvent
down
,
PointerUpEvent
up
})
{
void
handleTapUp
({
required
PointerDownEvent
down
,
required
PointerUpEvent
up
})
{
final
TapUpDetails
details
=
TapUpDetails
(
final
TapUpDetails
details
=
TapUpDetails
(
globalPosition:
up
.
position
,
globalPosition:
up
.
position
,
localPosition:
up
.
localPosition
,
localPosition:
up
.
localPosition
,
...
@@ -519,15 +518,15 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -519,15 +518,15 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
switch
(
down
.
buttons
)
{
switch
(
down
.
buttons
)
{
case
kPrimaryButton:
case
kPrimaryButton:
if
(
onTapUp
!=
null
)
if
(
onTapUp
!=
null
)
invokeCallback
<
void
>(
'onTapUp'
,
()
=>
onTapUp
(
details
));
invokeCallback
<
void
>(
'onTapUp'
,
()
=>
onTapUp
!
(
details
));
if
(
onTap
!=
null
)
if
(
onTap
!=
null
)
invokeCallback
<
void
>(
'onTap'
,
onTap
);
invokeCallback
<
void
>(
'onTap'
,
onTap
!
);
break
;
break
;
case
kSecondaryButton:
case
kSecondaryButton:
if
(
onSecondaryTapUp
!=
null
)
if
(
onSecondaryTapUp
!=
null
)
invokeCallback
<
void
>(
'onSecondaryTapUp'
,
()
=>
onSecondaryTapUp
(
details
));
invokeCallback
<
void
>(
'onSecondaryTapUp'
,
()
=>
onSecondaryTapUp
!
(
details
));
if
(
onSecondaryTap
!=
null
)
if
(
onSecondaryTap
!=
null
)
invokeCallback
<
void
>(
'onSecondaryTap'
,
()
=>
onSecondaryTap
());
invokeCallback
<
void
>(
'onSecondaryTap'
,
()
=>
onSecondaryTap
!
());
break
;
break
;
default
:
default
:
}
}
...
@@ -535,16 +534,16 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
...
@@ -535,16 +534,16 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
@protected
@protected
@override
@override
void
handleTapCancel
({
PointerDownEvent
down
,
PointerCancelEvent
cancel
,
String
reason
})
{
void
handleTapCancel
({
required
PointerDownEvent
down
,
PointerCancelEvent
?
cancel
,
required
String
reason
})
{
final
String
note
=
reason
==
''
?
reason
:
'
$reason
'
;
final
String
note
=
reason
==
''
?
reason
:
'
$reason
'
;
switch
(
down
.
buttons
)
{
switch
(
down
.
buttons
)
{
case
kPrimaryButton:
case
kPrimaryButton:
if
(
onTapCancel
!=
null
)
if
(
onTapCancel
!=
null
)
invokeCallback
<
void
>(
'
${note}
onTapCancel'
,
onTapCancel
);
invokeCallback
<
void
>(
'
${note}
onTapCancel'
,
onTapCancel
!
);
break
;
break
;
case
kSecondaryButton:
case
kSecondaryButton:
if
(
onSecondaryTapCancel
!=
null
)
if
(
onSecondaryTapCancel
!=
null
)
invokeCallback
<
void
>(
'
${note}
onSecondaryTapCancel'
,
onSecondaryTapCancel
);
invokeCallback
<
void
>(
'
${note}
onSecondaryTapCancel'
,
onSecondaryTapCancel
!
);
break
;
break
;
default
:
default
:
}
}
...
...
packages/flutter/lib/src/gestures/team.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'arena.dart'
;
import
'arena.dart'
;
import
'binding.dart'
;
import
'binding.dart'
;
...
@@ -27,8 +26,8 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
...
@@ -27,8 +26,8 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
final
int
_pointer
;
final
int
_pointer
;
bool
_resolved
=
false
;
bool
_resolved
=
false
;
GestureArenaMember
_winner
;
GestureArenaMember
?
_winner
;
GestureArenaEntry
_entry
;
GestureArenaEntry
?
_entry
;
@override
@override
void
acceptGesture
(
int
pointer
)
{
void
acceptGesture
(
int
pointer
)
{
...
@@ -40,7 +39,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
...
@@ -40,7 +39,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
if
(
member
!=
_winner
)
if
(
member
!=
_winner
)
member
.
rejectGesture
(
pointer
);
member
.
rejectGesture
(
pointer
);
}
}
_winner
.
acceptGesture
(
pointer
);
_winner
!
.
acceptGesture
(
pointer
);
}
}
@override
@override
...
@@ -54,7 +53,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
...
@@ -54,7 +53,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
void
_close
()
{
void
_close
()
{
assert
(!
_resolved
);
assert
(!
_resolved
);
_resolved
=
true
;
_resolved
=
true
;
final
_CombiningGestureArenaMember
combiner
=
_owner
.
_combiners
.
remove
(
_pointer
);
final
_CombiningGestureArenaMember
?
combiner
=
_owner
.
_combiners
.
remove
(
_pointer
);
assert
(
combiner
==
this
);
assert
(
combiner
==
this
);
}
}
...
@@ -62,7 +61,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
...
@@ -62,7 +61,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
assert
(!
_resolved
);
assert
(!
_resolved
);
assert
(
_pointer
==
pointer
);
assert
(
_pointer
==
pointer
);
_members
.
add
(
member
);
_members
.
add
(
member
);
_entry
??=
GestureBinding
.
instance
.
gestureArena
.
add
(
pointer
,
this
);
_entry
??=
GestureBinding
.
instance
!
.
gestureArena
.
add
(
pointer
,
this
);
return
_CombiningGestureArenaEntry
(
this
,
member
);
return
_CombiningGestureArenaEntry
(
this
,
member
);
}
}
...
@@ -73,11 +72,11 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
...
@@ -73,11 +72,11 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
_members
.
remove
(
member
);
_members
.
remove
(
member
);
member
.
rejectGesture
(
_pointer
);
member
.
rejectGesture
(
_pointer
);
if
(
_members
.
isEmpty
)
if
(
_members
.
isEmpty
)
_entry
.
resolve
(
disposition
);
_entry
!
.
resolve
(
disposition
);
}
else
{
}
else
{
assert
(
disposition
==
GestureDisposition
.
accepted
);
assert
(
disposition
==
GestureDisposition
.
accepted
);
_winner
??=
_owner
.
captain
??
member
;
_winner
??=
_owner
.
captain
??
member
;
_entry
.
resolve
(
disposition
);
_entry
!
.
resolve
(
disposition
);
}
}
}
}
}
}
...
@@ -131,7 +130,7 @@ class GestureArenaTeam {
...
@@ -131,7 +130,7 @@ class GestureArenaTeam {
/// If not null, when any one of the [GestureArenaTeam] members claims victory
/// If not null, when any one of the [GestureArenaTeam] members claims victory
/// the captain accepts the gesture.
/// the captain accepts the gesture.
/// If null, the member that claims a victory accepts the gesture.
/// If null, the member that claims a victory accepts the gesture.
GestureArenaMember
captain
;
GestureArenaMember
?
captain
;
/// Adds a new member to the arena on behalf of this team.
/// Adds a new member to the arena on behalf of this team.
///
///
...
...
packages/flutter/lib/src/gestures/velocity_tracker.dart
View file @
00dcd5f4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'dart:ui'
show
Offset
;
import
'dart:ui'
show
Offset
;
...
@@ -19,7 +18,7 @@ class Velocity {
...
@@ -19,7 +18,7 @@ class Velocity {
///
///
/// The [pixelsPerSecond] argument must not be null.
/// The [pixelsPerSecond] argument must not be null.
const
Velocity
({
const
Velocity
({
@
required
this
.
pixelsPerSecond
,
required
this
.
pixelsPerSecond
,
})
:
assert
(
pixelsPerSecond
!=
null
);
})
:
assert
(
pixelsPerSecond
!=
null
);
/// A velocity that isn't moving at all.
/// A velocity that isn't moving at all.
...
@@ -95,10 +94,10 @@ class VelocityEstimate {
...
@@ -95,10 +94,10 @@ class VelocityEstimate {
///
///
/// [pixelsPerSecond], [confidence], [duration], and [offset] must not be null.
/// [pixelsPerSecond], [confidence], [duration], and [offset] must not be null.
const
VelocityEstimate
({
const
VelocityEstimate
({
@
required
this
.
pixelsPerSecond
,
required
this
.
pixelsPerSecond
,
@
required
this
.
confidence
,
required
this
.
confidence
,
@
required
this
.
duration
,
required
this
.
duration
,
@
required
this
.
offset
,
required
this
.
offset
,
})
:
assert
(
pixelsPerSecond
!=
null
),
})
:
assert
(
pixelsPerSecond
!=
null
),
assert
(
confidence
!=
null
),
assert
(
confidence
!=
null
),
assert
(
duration
!=
null
),
assert
(
duration
!=
null
),
...
@@ -154,7 +153,7 @@ class VelocityTracker {
...
@@ -154,7 +153,7 @@ class VelocityTracker {
static
const
int
_minSampleSize
=
3
;
static
const
int
_minSampleSize
=
3
;
// Circular buffer; current sample at _index.
// Circular buffer; current sample at _index.
final
List
<
_PointAtTime
>
_samples
=
List
<
_PointAtTime
>(
_historySiz
e
);
final
List
<
_PointAtTime
?>
_samples
=
List
<
_PointAtTime
?>.
filled
(
_historySize
,
null
,
growable:
fals
e
);
int
_index
=
0
;
int
_index
=
0
;
/// Adds a position as the given time to the tracker.
/// Adds a position as the given time to the tracker.
...
@@ -171,7 +170,7 @@ class VelocityTracker {
...
@@ -171,7 +170,7 @@ class VelocityTracker {
/// Information is added using [addPosition].
/// Information is added using [addPosition].
///
///
/// Returns null if there is no data on which to base an estimate.
/// 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
>[];
final
List
<
double
>
w
=
<
double
>[];
final
List
<
double
>
w
=
<
double
>[];
...
@@ -179,7 +178,7 @@ class VelocityTracker {
...
@@ -179,7 +178,7 @@ class VelocityTracker {
int
sampleCount
=
0
;
int
sampleCount
=
0
;
int
index
=
_index
;
int
index
=
_index
;
final
_PointAtTime
newestSample
=
_samples
[
index
];
final
_PointAtTime
?
newestSample
=
_samples
[
index
];
if
(
newestSample
==
null
)
if
(
newestSample
==
null
)
return
null
;
return
null
;
...
@@ -189,7 +188,7 @@ class VelocityTracker {
...
@@ -189,7 +188,7 @@ class VelocityTracker {
// Starting with the most recent PointAtTime sample, iterate backwards while
// Starting with the most recent PointAtTime sample, iterate backwards while
// the samples represent continuous motion.
// the samples represent continuous motion.
do
{
do
{
final
_PointAtTime
sample
=
_samples
[
index
];
final
_PointAtTime
?
sample
=
_samples
[
index
];
if
(
sample
==
null
)
if
(
sample
==
null
)
break
;
break
;
...
@@ -212,10 +211,10 @@ class VelocityTracker {
...
@@ -212,10 +211,10 @@ class VelocityTracker {
if
(
sampleCount
>=
_minSampleSize
)
{
if
(
sampleCount
>=
_minSampleSize
)
{
final
LeastSquaresSolver
xSolver
=
LeastSquaresSolver
(
time
,
x
,
w
);
final
LeastSquaresSolver
xSolver
=
LeastSquaresSolver
(
time
,
x
,
w
);
final
PolynomialFit
xFit
=
xSolver
.
solve
(
2
);
final
PolynomialFit
?
xFit
=
xSolver
.
solve
(
2
);
if
(
xFit
!=
null
)
{
if
(
xFit
!=
null
)
{
final
LeastSquaresSolver
ySolver
=
LeastSquaresSolver
(
time
,
y
,
w
);
final
LeastSquaresSolver
ySolver
=
LeastSquaresSolver
(
time
,
y
,
w
);
final
PolynomialFit
yFit
=
ySolver
.
solve
(
2
);
final
PolynomialFit
?
yFit
=
ySolver
.
solve
(
2
);
if
(
yFit
!=
null
)
{
if
(
yFit
!=
null
)
{
return
VelocityEstimate
(
// convert from pixels/ms to pixels/s
return
VelocityEstimate
(
// convert from pixels/ms to pixels/s
pixelsPerSecond:
Offset
(
xFit
.
coefficients
[
1
]
*
1000
,
yFit
.
coefficients
[
1
]
*
1000
),
pixelsPerSecond:
Offset
(
xFit
.
coefficients
[
1
]
*
1000
,
yFit
.
coefficients
[
1
]
*
1000
),
...
@@ -245,7 +244,7 @@ class VelocityTracker {
...
@@ -245,7 +244,7 @@ class VelocityTracker {
/// Returns [Velocity.zero] if there is no data from which to compute an
/// Returns [Velocity.zero] if there is no data from which to compute an
/// estimate or if the estimated 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
Velocity
.
zero
;
return
Velocity
.
zero
;
return
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
);
return
Velocity
(
pixelsPerSecond:
estimate
.
pixelsPerSecond
);
...
...
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