From 86733471ebb47ab722399b56c9db295101f2930a Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 11 Nov 2022 12:41:22 +0600 Subject: [PATCH] fix(macos): window button events not working --- lib/src/platform_window_buttons.dart | 41 ++++++++++++---------------- lib/src/tools/gesture_builder.dart | 10 +++++++ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lib/src/platform_window_buttons.dart b/lib/src/platform_window_buttons.dart index a338342..ecadf55 100644 --- a/lib/src/platform_window_buttons.dart +++ b/lib/src/platform_window_buttons.dart @@ -157,31 +157,27 @@ class _PlatformWindowButtonsState extends State children: [ MouseRegion( cursor: SystemMouseCursors.click, - child: GestureDetector( - behavior: HitTestBehavior.opaque, + child: GestureBuilder( onTap: widget.onClose ?? config?.onClose, - child: GestureBuilder( - builder: (context, states) { - return Container( - height: 18, - width: 18, - decoration: states.isPressing - ? decoration.copyWith( - color: Colors.red[800], - ) - : decoration, - ); - }, - ), + builder: (context, states) { + return Container( + height: 18, + width: 18, + decoration: states.isPressing + ? decoration.copyWith( + color: Colors.red[800], + ) + : decoration, + ); + }, ), ), const SizedBox(width: 4), MouseRegion( cursor: SystemMouseCursors.click, - child: GestureDetector( - behavior: HitTestBehavior.opaque, + child: GestureBuilder( onTap: widget.onMinimize ?? config?.onMinimize, - child: GestureBuilder(builder: (context, states) { + builder: (context, states) { return Container( height: 18, width: 18, @@ -191,18 +187,17 @@ class _PlatformWindowButtonsState extends State : Colors.orange[200], ), ); - }), + }, ), ), const SizedBox(width: 4), MouseRegion( cursor: SystemMouseCursors.click, - child: GestureDetector( - behavior: HitTestBehavior.opaque, + child: GestureBuilder( onTap: (widget.isMaximized ?? config?.isMaximized) == true ? (widget.onMaximize ?? config?.onMaximize) : (widget.onRestore ?? config?.onRestore), - child: GestureBuilder(builder: (context, states) { + builder: (context, states) { return Container( height: 18, width: 18, @@ -211,7 +206,7 @@ class _PlatformWindowButtonsState extends State states.isPressing ? Colors.green[800] : Colors.green[400], ), ); - }), + }, ), ), ], diff --git a/lib/src/tools/gesture_builder.dart b/lib/src/tools/gesture_builder.dart index 20f21d5..cd372ab 100644 --- a/lib/src/tools/gesture_builder.dart +++ b/lib/src/tools/gesture_builder.dart @@ -1,4 +1,5 @@ import 'package:flutter/cupertino.dart'; +import 'package:flutter/gestures.dart'; class GestureStates { bool isPressing = false; @@ -7,10 +8,16 @@ class GestureStates { } class GestureBuilder extends StatefulWidget { + final VoidCallback? onTap; + final ValueChanged? onHover; + final ValueChanged? onFocusChange; final Widget Function(BuildContext context, GestureStates states) builder; const GestureBuilder({ Key? key, required this.builder, + this.onTap, + this.onHover, + this.onFocusChange, }) : super(key: key); @override @@ -27,8 +34,10 @@ class _GestureBuilderState extends State { setState(() { states.isFocused = value; }); + widget.onFocusChange?.call(value); }, child: MouseRegion( + onHover: widget.onHover, onEnter: (event) { setState(() { states.isHovering = true; @@ -40,6 +49,7 @@ class _GestureBuilderState extends State { }); }, child: GestureDetector( + onTap: widget.onTap, onTapDown: (_) { setState(() { states.isPressing = true;