1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import 'package:flutter/gestures.dart';
- import 'package:flutter/material.dart';
- class SingleTouchRecognizer extends StatelessWidget {
- Widget? child;
- SingleTouchRecognizer({this.child});
- @override
- Widget build(BuildContext context) {
- return RawGestureDetector(
- gestures: <Type, GestureRecognizerFactory>{
- _SingleTouchRecognizer: GestureRecognizerFactoryWithHandlers<_SingleTouchRecognizer>(
- () => _SingleTouchRecognizer(),
- (_SingleTouchRecognizer instance) {},
- ),
- },
- child: child,
- );
- }
- }
- class _SingleTouchRecognizer extends OneSequenceGestureRecognizer {
- int _p = 0;
- @override
- void addAllowedPointer(PointerDownEvent event) {
- //first register the current pointer so that related events will be handled by this recognizer
- startTrackingPointer(event.pointer);
- //ignore event if another event is already in progress
- if (_p == 0) {
- resolve(GestureDisposition.rejected);
- _p = event.pointer;
- } else {
- resolve(GestureDisposition.accepted);
- }
- }
- @override
- // TODO: implement debugDescription
- String get debugDescription => "";
- @override
- void didStopTrackingLastPointer(int pointer) {
- // TODO: implement didStopTrackingLastPointer
- }
- @override
- void handleEvent(PointerEvent event) {
- if (!event.down && event.pointer == _p) {
- _p = 0;
- }
- }
- }
|