This commit is contained in:
Erick Zanardo
2020-05-13 12:03:06 -03:00
parent b901063d63
commit aa1ffced6f
4 changed files with 252 additions and 239 deletions

View File

@@ -22,11 +22,7 @@ class MyGame extends Game with MultiTouchTapDetector {
@override @override
void onTapDown(int pointerId, TapDownDetails details) { void onTapDown(int pointerId, TapDownDetails details) {
_taps[pointerId] = Rect.fromLTWH( _taps[pointerId] = Rect.fromLTWH(
details.globalPosition.dx, details.globalPosition.dx, details.globalPosition.dy, 50, 50);
details.globalPosition.dy,
50,
50
);
} }
@override @override

View File

@@ -26,11 +26,7 @@ class MyGame extends Game with MultiTouchTapDetector, PanDetector {
@override @override
void onTapDown(int pointerId, TapDownDetails details) { void onTapDown(int pointerId, TapDownDetails details) {
_taps[pointerId] = Rect.fromLTWH( _taps[pointerId] = Rect.fromLTWH(
details.globalPosition.dx, details.globalPosition.dx, details.globalPosition.dy, 50, 50);
details.globalPosition.dy,
50,
50
);
} }
@override @override
@@ -57,8 +53,10 @@ class MyGame extends Game with MultiTouchTapDetector, PanDetector {
@override @override
void onPanEnd(details) { void onPanEnd(details) {
_panRect = Rect.fromLTRB( _panRect = Rect.fromLTRB(
_start.dx, _start.dy, _start.dx,
_end.dx, _end.dy, _start.dy,
_end.dx,
_end.dy,
); );
} }

View File

@@ -64,31 +64,41 @@ class GestureDetector extends StatelessWidget {
}) : assert(excludeFromSemantics != null), }) : assert(excludeFromSemantics != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(() { assert(() {
final bool haveVerticalDrag = onVerticalDragStart != null || onVerticalDragUpdate != null || onVerticalDragEnd != null; final bool haveVerticalDrag = onVerticalDragStart != null ||
final bool haveHorizontalDrag = onHorizontalDragStart != null || onHorizontalDragUpdate != null || onHorizontalDragEnd != null; onVerticalDragUpdate != null ||
final bool havePan = onPanStart != null || onPanUpdate != null || onPanEnd != null; onVerticalDragEnd != null;
final bool haveScale = onScaleStart != null || onScaleUpdate != null || onScaleEnd != null; final bool haveHorizontalDrag = onHorizontalDragStart != null ||
onHorizontalDragUpdate != null ||
onHorizontalDragEnd != null;
final bool havePan =
onPanStart != null || onPanUpdate != null || onPanEnd != null;
final bool haveScale = onScaleStart != null ||
onScaleUpdate != null ||
onScaleEnd != null;
final bool haveTap = onTap != null || onTapCancel != null || onTapUp != null || onTapDown != null; final bool haveTap = onTap != null ||
final bool haveMultiTap = onMultiTap != null || onMultiTapCancel != null || onMultiTapUp != null || onMultiTapDown != null; onTapCancel != null ||
onTapUp != null ||
onTapDown != null;
final bool haveMultiTap = onMultiTap != null ||
onMultiTapCancel != null ||
onMultiTapUp != null ||
onMultiTapDown != null;
if (havePan || haveScale) { if (havePan || haveScale) {
if (havePan && haveScale) { if (havePan && haveScale) {
throw FlutterError.fromParts(<DiagnosticsNode>[ throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Incorrect GestureDetector arguments.'), ErrorSummary('Incorrect GestureDetector arguments.'),
ErrorDescription( ErrorDescription(
'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan.' 'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan.'),
),
ErrorHint('Just use the scale gesture recognizer.') ErrorHint('Just use the scale gesture recognizer.')
]); ]);
} }
final String recognizer = havePan ? 'pan' : 'scale'; final String recognizer = havePan ? 'pan' : 'scale';
if (haveVerticalDrag && haveHorizontalDrag) { if (haveVerticalDrag && haveHorizontalDrag) {
throw FlutterError( throw FlutterError('Incorrect GestureDetector arguments.\n'
'Incorrect GestureDetector arguments.\n'
'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer ' 'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer '
'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.' 'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.');
);
} }
} }
if (haveTap || haveMultiTap) { if (haveTap || haveMultiTap) {
@@ -96,8 +106,7 @@ class GestureDetector extends StatelessWidget {
throw FlutterError.fromParts(<DiagnosticsNode>[ throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Incorrect GestureDetector arguments.'), ErrorSummary('Incorrect GestureDetector arguments.'),
ErrorDescription( ErrorDescription(
'Having both a tap gesture recognizer and a multi tap gesture recognizer is redundant.' 'Having both a tap gesture recognizer and a multi tap gesture recognizer is redundant.'),
),
ErrorHint('Just use one of the recognizers.') ErrorHint('Just use one of the recognizers.')
]); ]);
} }
@@ -453,18 +462,18 @@ class GestureDetector extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{}; final Map<Type, GestureRecognizerFactory> gestures =
<Type, GestureRecognizerFactory>{};
if ( if (onTapDown != null ||
onTapDown != null ||
onTapUp != null || onTapUp != null ||
onTap != null || onTap != null ||
onTapCancel != null || onTapCancel != null ||
onSecondaryTapDown != null || onSecondaryTapDown != null ||
onSecondaryTapUp != null || onSecondaryTapUp != null ||
onSecondaryTapCancel != null onSecondaryTapCancel != null) {
) { gestures[TapGestureRecognizer] =
gestures[TapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>( GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
() => TapGestureRecognizer(debugOwner: this), () => TapGestureRecognizer(debugOwner: this),
(TapGestureRecognizer instance) { (TapGestureRecognizer instance) {
instance instance
@@ -480,7 +489,8 @@ class GestureDetector extends StatelessWidget {
} }
if (onDoubleTap != null) { if (onDoubleTap != null) {
gestures[DoubleTapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>( gestures[DoubleTapGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
() => DoubleTapGestureRecognizer(debugOwner: this), () => DoubleTapGestureRecognizer(debugOwner: this),
(DoubleTapGestureRecognizer instance) { (DoubleTapGestureRecognizer instance) {
instance.onDoubleTap = onDoubleTap; instance.onDoubleTap = onDoubleTap;
@@ -493,14 +503,15 @@ class GestureDetector extends StatelessWidget {
onLongPressStart != null || onLongPressStart != null ||
onLongPressMoveUpdate != null || onLongPressMoveUpdate != null ||
onLongPressEnd != null) { onLongPressEnd != null) {
gestures[LongPressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>( gestures[LongPressGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
() => LongPressGestureRecognizer(debugOwner: this), () => LongPressGestureRecognizer(debugOwner: this),
(LongPressGestureRecognizer instance) { (LongPressGestureRecognizer instance) {
instance instance
..onLongPress = onLongPress ..onLongPress = onLongPress
..onLongPressStart = onLongPressStart ..onLongPressStart = onLongPressStart
..onLongPressMoveUpdate = onLongPressMoveUpdate ..onLongPressMoveUpdate = onLongPressMoveUpdate
..onLongPressEnd =onLongPressEnd ..onLongPressEnd = onLongPressEnd
..onLongPressUp = onLongPressUp; ..onLongPressUp = onLongPressUp;
}, },
); );
@@ -511,7 +522,8 @@ class GestureDetector extends StatelessWidget {
onVerticalDragUpdate != null || onVerticalDragUpdate != null ||
onVerticalDragEnd != null || onVerticalDragEnd != null ||
onVerticalDragCancel != null) { onVerticalDragCancel != null) {
gestures[VerticalDragGestureRecognizer] = GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>( gestures[VerticalDragGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer(debugOwner: this), () => VerticalDragGestureRecognizer(debugOwner: this),
(VerticalDragGestureRecognizer instance) { (VerticalDragGestureRecognizer instance) {
instance instance
@@ -530,7 +542,8 @@ class GestureDetector extends StatelessWidget {
onHorizontalDragUpdate != null || onHorizontalDragUpdate != null ||
onHorizontalDragEnd != null || onHorizontalDragEnd != null ||
onHorizontalDragCancel != null) { onHorizontalDragCancel != null) {
gestures[HorizontalDragGestureRecognizer] = GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>( gestures[HorizontalDragGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>(
() => HorizontalDragGestureRecognizer(debugOwner: this), () => HorizontalDragGestureRecognizer(debugOwner: this),
(HorizontalDragGestureRecognizer instance) { (HorizontalDragGestureRecognizer instance) {
instance instance
@@ -549,7 +562,8 @@ class GestureDetector extends StatelessWidget {
onPanUpdate != null || onPanUpdate != null ||
onPanEnd != null || onPanEnd != null ||
onPanCancel != null) { onPanCancel != null) {
gestures[PanGestureRecognizer] = GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>( gestures[PanGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>(
() => PanGestureRecognizer(debugOwner: this), () => PanGestureRecognizer(debugOwner: this),
(PanGestureRecognizer instance) { (PanGestureRecognizer instance) {
instance instance
@@ -564,7 +578,8 @@ class GestureDetector extends StatelessWidget {
} }
if (onScaleStart != null || onScaleUpdate != null || onScaleEnd != null) { if (onScaleStart != null || onScaleUpdate != null || onScaleEnd != null) {
gestures[ScaleGestureRecognizer] = GestureRecognizerFactoryWithHandlers<ScaleGestureRecognizer>( gestures[ScaleGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<ScaleGestureRecognizer>(
() => ScaleGestureRecognizer(debugOwner: this), () => ScaleGestureRecognizer(debugOwner: this),
(ScaleGestureRecognizer instance) { (ScaleGestureRecognizer instance) {
instance instance
@@ -579,7 +594,8 @@ class GestureDetector extends StatelessWidget {
onForcePressPeak != null || onForcePressPeak != null ||
onForcePressUpdate != null || onForcePressUpdate != null ||
onForcePressEnd != null) { onForcePressEnd != null) {
gestures[ForcePressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<ForcePressGestureRecognizer>( gestures[ForcePressGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<ForcePressGestureRecognizer>(
() => ForcePressGestureRecognizer(debugOwner: this), () => ForcePressGestureRecognizer(debugOwner: this),
(ForcePressGestureRecognizer instance) { (ForcePressGestureRecognizer instance) {
instance instance
@@ -591,13 +607,12 @@ class GestureDetector extends StatelessWidget {
); );
} }
if ( if (onMultiTapDown != null ||
onMultiTapDown != null ||
onMultiTapUp != null || onMultiTapUp != null ||
onMultiTap != null || onMultiTap != null ||
onMultiTapCancel != null onMultiTapCancel != null) {
) { gestures[MultiTapGestureRecognizer] =
gestures[MultiTapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<MultiTapGestureRecognizer>( GestureRecognizerFactoryWithHandlers<MultiTapGestureRecognizer>(
() => MultiTapGestureRecognizer(debugOwner: this), () => MultiTapGestureRecognizer(debugOwner: this),
(MultiTapGestureRecognizer instance) { (MultiTapGestureRecognizer instance) {
instance instance
@@ -616,9 +631,11 @@ class GestureDetector extends StatelessWidget {
child: child, child: child,
); );
} }
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(EnumProperty<DragStartBehavior>('startBehavior', dragStartBehavior)); properties.add(
EnumProperty<DragStartBehavior>('startBehavior', dragStartBehavior));
} }
} }

View File

@@ -22,9 +22,8 @@ Widget _applyGesturesDetectors(Game game, Widget child) {
return flame_detector.GestureDetector( return flame_detector.GestureDetector(
// Taps // Taps
onTap: game is TapDetector ? () => (game as TapDetector).onTap() : null, onTap: game is TapDetector ? () => (game as TapDetector).onTap() : null,
onTapCancel: game is TapDetector onTapCancel:
? () => (game as TapDetector).onTapCancel() game is TapDetector ? () => (game as TapDetector).onTapCancel() : null,
: null,
onTapDown: game is TapDetector onTapDown: game is TapDetector
? (TapDownDetails d) => (game as TapDetector).onTapDown(d) ? (TapDownDetails d) => (game as TapDetector).onTapDown(d)
: null, : null,
@@ -33,15 +32,20 @@ Widget _applyGesturesDetectors(Game game, Widget child) {
: null, : null,
// MultiTaps // MultiTaps
onMultiTap: game is MultiTouchTapDetector ? (int pointerId) => (game as MultiTouchTapDetector).onTap(pointerId) : null, onMultiTap: game is MultiTouchTapDetector
? (int pointerId) => (game as MultiTouchTapDetector).onTap(pointerId)
: null,
onMultiTapCancel: game is MultiTouchTapDetector onMultiTapCancel: game is MultiTouchTapDetector
? (int pointerId) => (game as MultiTouchTapDetector).onTapCancel(pointerId) ? (int pointerId) =>
(game as MultiTouchTapDetector).onTapCancel(pointerId)
: null, : null,
onMultiTapDown: game is MultiTouchTapDetector onMultiTapDown: game is MultiTouchTapDetector
? (int pointerId, TapDownDetails d) => (game as MultiTouchTapDetector).onTapDown(pointerId, d) ? (int pointerId, TapDownDetails d) =>
(game as MultiTouchTapDetector).onTapDown(pointerId, d)
: null, : null,
onMultiTapUp: game is MultiTouchTapDetector onMultiTapUp: game is MultiTouchTapDetector
? (int pointerId, TapUpDetails d) => (game as MultiTouchTapDetector).onTapUp(pointerId, d) ? (int pointerId, TapUpDetails d) =>
(game as MultiTouchTapDetector).onTapUp(pointerId, d)
: null, : null,
// Secondary taps // Secondary taps
@@ -50,8 +54,7 @@ Widget _applyGesturesDetectors(Game game, Widget child) {
(game as SecondaryTapDetector).onSecondaryTapDown(d) (game as SecondaryTapDetector).onSecondaryTapDown(d)
: null, : null,
onSecondaryTapUp: game is SecondaryTapDetector onSecondaryTapUp: game is SecondaryTapDetector
? (TapUpDetails d) => ? (TapUpDetails d) => (game as SecondaryTapDetector).onSecondaryTapUp(d)
(game as SecondaryTapDetector).onSecondaryTapUp(d)
: null, : null,
onSecondaryTapCancel: game is SecondaryTapDetector onSecondaryTapCancel: game is SecondaryTapDetector
? () => (game as SecondaryTapDetector).onSecondaryTapCancel() ? () => (game as SecondaryTapDetector).onSecondaryTapCancel()
@@ -155,9 +158,8 @@ Widget _applyGesturesDetectors(Game game, Widget child) {
onPanEnd: game is PanDetector onPanEnd: game is PanDetector
? (DragEndDetails d) => (game as PanDetector).onPanEnd(d) ? (DragEndDetails d) => (game as PanDetector).onPanEnd(d)
: null, : null,
onPanCancel: game is PanDetector onPanCancel:
? () => (game as PanDetector).onPanCancel() game is PanDetector ? () => (game as PanDetector).onPanCancel() : null,
: null,
// Scales // Scales
onScaleStart: game is ScaleDetector onScaleStart: game is ScaleDetector