|
|
@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 单点触摸的方案:https://xbuba.com/questions/51712287
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OnlyOnePointerRecognizer extends OneSequenceGestureRecognizer {
|
|
|
|
|
|
|
|
int _p = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void addAllowedPointer(PointerDownEvent event) {
|
|
|
|
|
|
|
|
startTrackingPointer(event.pointer);
|
|
|
|
|
|
|
|
if (_p == 0) {
|
|
|
|
|
|
|
|
resolve(GestureDisposition.rejected);
|
|
|
|
|
|
|
|
_p = event.pointer;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resolve(GestureDisposition.accepted);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
String get debugDescription => 'only one pointer recognizer';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void didStopTrackingLastPointer(int pointer) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void handleEvent(PointerEvent event) {
|
|
|
|
|
|
|
|
if (!event.down && event.pointer == _p) {
|
|
|
|
|
|
|
|
_p = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OnlyOnePointerRecognizerWidget extends StatelessWidget {
|
|
|
|
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OnlyOnePointerRecognizerWidget({this.child});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
|
|
return RawGestureDetector(
|
|
|
|
|
|
|
|
gestures: <Type, GestureRecognizerFactory>{
|
|
|
|
|
|
|
|
OnlyOnePointerRecognizer:
|
|
|
|
|
|
|
|
GestureRecognizerFactoryWithHandlers<OnlyOnePointerRecognizer>(
|
|
|
|
|
|
|
|
() => OnlyOnePointerRecognizer(),
|
|
|
|
|
|
|
|
(OnlyOnePointerRecognizer instance) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
child: child,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|