Skip to content

Commit

Permalink
fix(macos): window button events not working
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 11, 2022
1 parent c834d14 commit 8673347
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
41 changes: 18 additions & 23 deletions lib/src/platform_window_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,27 @@ class _PlatformWindowButtonsState extends State<PlatformWindowButtons>
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,
Expand All @@ -191,18 +187,17 @@ class _PlatformWindowButtonsState extends State<PlatformWindowButtons>
: 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,
Expand All @@ -211,7 +206,7 @@ class _PlatformWindowButtonsState extends State<PlatformWindowButtons>
states.isPressing ? Colors.green[800] : Colors.green[400],
),
);
}),
},
),
),
],
Expand Down
10 changes: 10 additions & 0 deletions lib/src/tools/gesture_builder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';

class GestureStates {
bool isPressing = false;
Expand All @@ -7,10 +8,16 @@ class GestureStates {
}

class GestureBuilder extends StatefulWidget {
final VoidCallback? onTap;
final ValueChanged<PointerHoverEvent>? onHover;
final ValueChanged<bool>? 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
Expand All @@ -27,8 +34,10 @@ class _GestureBuilderState extends State<GestureBuilder> {
setState(() {
states.isFocused = value;
});
widget.onFocusChange?.call(value);
},
child: MouseRegion(
onHover: widget.onHover,
onEnter: (event) {
setState(() {
states.isHovering = true;
Expand All @@ -40,6 +49,7 @@ class _GestureBuilderState extends State<GestureBuilder> {
});
},
child: GestureDetector(
onTap: widget.onTap,
onTapDown: (_) {
setState(() {
states.isPressing = true;
Expand Down

0 comments on commit 8673347

Please sign in to comment.