SingleTouchWidget.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import 'package:flutter/gestures.dart';
  2. import 'package:flutter/material.dart';
  3. class SingleTouchRecognizer extends StatelessWidget {
  4. Widget? child;
  5. SingleTouchRecognizer({this.child});
  6. @override
  7. Widget build(BuildContext context) {
  8. return RawGestureDetector(
  9. gestures: <Type, GestureRecognizerFactory>{
  10. _SingleTouchRecognizer: GestureRecognizerFactoryWithHandlers<_SingleTouchRecognizer>(
  11. () => _SingleTouchRecognizer(),
  12. (_SingleTouchRecognizer instance) {},
  13. ),
  14. },
  15. child: child,
  16. );
  17. }
  18. }
  19. class _SingleTouchRecognizer extends OneSequenceGestureRecognizer {
  20. int _p = 0;
  21. @override
  22. void addAllowedPointer(PointerDownEvent event) {
  23. //first register the current pointer so that related events will be handled by this recognizer
  24. startTrackingPointer(event.pointer);
  25. //ignore event if another event is already in progress
  26. if (_p == 0) {
  27. resolve(GestureDisposition.rejected);
  28. _p = event.pointer;
  29. } else {
  30. resolve(GestureDisposition.accepted);
  31. }
  32. }
  33. @override
  34. // TODO: implement debugDescription
  35. String get debugDescription => "";
  36. @override
  37. void didStopTrackingLastPointer(int pointer) {
  38. // TODO: implement didStopTrackingLastPointer
  39. }
  40. @override
  41. void handleEvent(PointerEvent event) {
  42. if (!event.down && event.pointer == _p) {
  43. _p = 0;
  44. }
  45. }
  46. }