diff --git a/lib/components/gesture.dart b/lib/components/gesture.dart index 6db2d40..bd345f2 100644 --- a/lib/components/gesture.dart +++ b/lib/components/gesture.dart @@ -1,58 +1,19 @@ part of 'components.dart'; -class MouseBackRecognizer extends BaseTapGestureRecognizer { - GestureTapDownCallback? onTapDown; - - MouseBackRecognizer({ - super.debugOwner, - super.supportedDevices, - super.allowedButtonsFilter, - }); - - @override - void handleTapCancel({ - required PointerDownEvent down, - PointerCancelEvent? cancel, - required String reason, - }) {} - - @override - void handleTapDown({required PointerDownEvent down}) { - final TapDownDetails details = TapDownDetails( - globalPosition: down.position, - localPosition: down.localPosition, - kind: getKindForPointer(down.pointer), - ); - - if (down.buttons == kBackMouseButton && onTapDown != null) { - invokeCallback('onTapDown', () => onTapDown!(details)); - } - } - - @override - void handleTapUp({ - required PointerDownEvent down, - required PointerUpEvent up, - }) {} -} - class MouseBackDetector extends StatelessWidget { const MouseBackDetector({super.key, required this.onTapDown, required this.child}); final Widget child; - final GestureTapDownCallback onTapDown; + final void Function() onTapDown; @override Widget build(BuildContext context) { - return RawGestureDetector( - gestures: { - MouseBackRecognizer: GestureRecognizerFactoryWithHandlers( - () => MouseBackRecognizer(), - (MouseBackRecognizer instance) { - instance.onTapDown = onTapDown; - }, - ), + return Listener( + onPointerDown: (event) { + if (event.buttons == kBackMouseButton) { + onTapDown(); + } }, behavior: HitTestBehavior.translucent, child: child, diff --git a/lib/main.dart b/lib/main.dart index 4f5d96a..305159b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -150,9 +150,7 @@ class _MyAppState extends State { ), }, child: MouseBackDetector( - onTapDown: (event) { - App.pop(); - }, + onTapDown: App.pop, child: WindowFrame(widget), ), );