remove custom guesture

This commit is contained in:
open-trade 2020-11-23 23:25:50 +08:00
parent d116251742
commit f86673ebcb
2 changed files with 2 additions and 211 deletions

View File

@ -1,104 +0,0 @@
import 'package:flutter/gestures.dart';
class MultiTouchGestureRecognizer extends MultiTapGestureRecognizer {
MultiTouchGestureRecognizerCallback onMultiTap;
var numberOfTouches = 0;
MultiTouchGestureRecognizer() {
this
..onTapDown = addTouch
..onTapUp = removeTouch
..onTapCancel = cancelTouch
..onTap = captureDefaultTap;
}
void addTouch(int pointer, TapDownDetails details) {
numberOfTouches++;
onMultiTap(numberOfTouches, true);
}
void removeTouch(int pointer, TapUpDetails details) {
numberOfTouches--;
onMultiTap(numberOfTouches, false);
}
void cancelTouch(int pointer) {
numberOfTouches = 0;
}
void captureDefaultTap(int pointer) {}
}
typedef MultiTouchGestureRecognizerCallback = void Function(
int touchCount, bool addOrRemove);
typedef OnUpdate(DragUpdateDetails details);
class CustomMultiDrag extends Drag {
CustomMultiDrag({this.events, this.offset});
List<PointerDownEvent> events;
Offset offset;
@override
void update(DragUpdateDetails details) {
var n = events.length;
print('$n $details');
}
@override
void end(DragEndDetails details) {
super.end(details);
}
}
typedef OnDisposeState();
// clone _ImmediatePointerState
class CustomPointerState extends MultiDragPointerState {
final OnDisposeState onDisposeState;
CustomPointerState(Offset initialPosition, PointerDeviceKind kind,
{this.onDisposeState})
: super(initialPosition, kind);
@override
void checkForResolutionAfterMove() {
assert(pendingDelta != null);
if (pendingDelta.distance > computeHitSlop(kind))
resolve(GestureDisposition.accepted);
}
@override
void accepted(GestureMultiDragStartCallback starter) {
starter(initialPosition);
}
@override
void dispose() {
onDisposeState.call();
super.dispose();
}
}
// clone ImmediateMultiDragGestureRecognizer
class CustomMultiDragGestureRecognizer
extends MultiDragGestureRecognizer<CustomPointerState> {
var events = List<PointerDownEvent>();
/// Create a gesture recognizer for tracking multiple pointers at once.
CustomMultiDragGestureRecognizer({
Object debugOwner,
PointerDeviceKind kind,
}) : super(debugOwner: debugOwner, kind: kind);
@override
CustomPointerState createNewPointerState(PointerDownEvent event) {
events.add(event);
return CustomPointerState(event.position, event.kind, onDisposeState: () {
events.remove(event);
});
}
@override
String get debugDescription => 'custom_multidrag';
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
import 'dart:ui' as ui;
@ -9,7 +8,6 @@ import 'dart:math' as math;
import 'package:tuple/tuple.dart';
import 'package:wakelock/wakelock.dart';
import 'common.dart';
import 'drag.dart';
import 'model.dart';
class RemotePage extends StatefulWidget {
@ -26,7 +24,6 @@ class _RemotePageState extends State<RemotePage> {
Timer _interval;
bool _showBar = true;
double _bottom = 0;
var _scaleMode = false;
double _xOffset = 0;
double _yOffset = 0;
double _scale = 1;
@ -167,15 +164,11 @@ class _RemotePageState extends State<RemotePage> {
position:
RelativeRect.fromLTRB(x + 20, y + 20, x + 20, y + 20),
items: [
PopupMenuItem<String>(
child: Text(_scaleMode ? 'Pan Mode' : 'Scale Mode'),
value: 'mode'),
PopupMenuItem<String>(child: Text('Test'), value: 'mode'),
],
elevation: 8.0,
);
if (value == 'mode') {
setState(() => _scaleMode = !_scaleMode);
}
if (value == 'mode') {}
}();
},
onDoubleTap: () {
@ -231,104 +224,6 @@ class _RemotePageState extends State<RemotePage> {
));
}
Map<Type, GestureRecognizerFactory> buildGuestures() {
var m = {
TapGestureRecognizer:
GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
() => TapGestureRecognizer(),
(TapGestureRecognizer instance) {
instance.onTap = () {
print('tap');
};
},
),
MultiTouchGestureRecognizer:
GestureRecognizerFactoryWithHandlers<MultiTouchGestureRecognizer>(
() => MultiTouchGestureRecognizer(),
(MultiTouchGestureRecognizer instance) {
instance.onMultiTap = (
touchCount,
addOrRemove,
) {
if (touchCount == 3 && addOrRemove) {
setState(() => _scaleMode = !_scaleMode);
}
};
},
),
CustomMultiDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<
CustomMultiDragGestureRecognizer>(
() => CustomMultiDragGestureRecognizer(),
(CustomMultiDragGestureRecognizer instance) {
instance
..onStart = (offset) {
return CustomMultiDrag(events: instance.events, offset: offset);
};
},
),
LongPressGestureRecognizer:
GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
() => LongPressGestureRecognizer(),
(LongPressGestureRecognizer instance) {
var x = 0.0;
var y = 0.0;
instance
..onLongPressStart = (details) {
x = details.globalPosition.dx;
y = details.globalPosition.dy;
}
..onLongPress = () {
() async {
print('long press: $x $y');
var value = await showMenu(
context: context,
position:
RelativeRect.fromLTRB(x + 20, y + 20, x + 20, y + 20),
items: [
PopupMenuItem<String>(
child: Text(_scaleMode ? 'Pan Mode' : 'Scale Mode'),
value: 'mode'),
],
elevation: 8.0,
);
if (value == 'mode') {
setState(() => _scaleMode = !_scaleMode);
}
}();
};
},
),
ScaleGestureRecognizer:
GestureRecognizerFactoryWithHandlers<ScaleGestureRecognizer>(
() => ScaleGestureRecognizer(),
(ScaleGestureRecognizer instance) {
instance
..onStart = (detail) {
print('scale start');
}
..onUpdate = (detail) {
print('$detail');
};
},
),
DoubleTapGestureRecognizer:
GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
() => DoubleTapGestureRecognizer(),
(DoubleTapGestureRecognizer instance) {
instance.onDoubleTap = () {
print('double tap');
};
},
),
};
if (_scaleMode) {
m.remove(CustomMultiDragGestureRecognizer);
} else {
m.remove(ScaleGestureRecognizer);
}
return m;
}
void close() {
msgbox('', 'Close', 'Are you sure to close the connection?', context);
}