Skip to content

Commit bfce325

Browse files
Added WindowDragArea.maximizable property (#1077)
* Fix window transparency Related issue: leanflutter/window_manager#293 * Custom `WindowDragArea` with `maximizable` prop Close #1056
1 parent 6b4e27f commit bfce325

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

client/macos/Runner/MainFlutterWindow.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FlutterMacOS
44
class MainFlutterWindow: NSWindow {
55
override func awakeFromNib() {
66
let flutterViewController = FlutterViewController.init()
7+
flutterViewController.backgroundColor = .clear
78
let windowFrame = self.frame
89
self.contentViewController = flutterViewController
910
self.setFrame(windowFrame, display: true)

package/lib/src/controls/window_drag_area.dart

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class WindowDragAreaControl extends StatelessWidget {
2525

2626
var contentCtrls =
2727
children.where((c) => c.name == "content" && c.isVisible);
28+
bool maximizable = control.attrBool("maximizable", true)!;
2829
bool disabled = control.isDisabled || parentDisabled;
2930

3031
if (contentCtrls.isEmpty) {
@@ -33,9 +34,40 @@ class WindowDragAreaControl extends StatelessWidget {
3334

3435
return constrainedControl(
3536
context,
36-
DragToMoveArea(
37+
WindowDragArea(
38+
maximizable: maximizable,
3739
child: createControl(control, contentCtrls.first.id, disabled)),
3840
parent,
3941
control);
4042
}
4143
}
44+
45+
class WindowDragArea extends StatelessWidget {
46+
final Widget child;
47+
final bool maximizable;
48+
49+
const WindowDragArea(
50+
{Key? key, required this.child, required this.maximizable})
51+
: super(key: key);
52+
53+
@override
54+
Widget build(BuildContext context) {
55+
return GestureDetector(
56+
behavior: HitTestBehavior.translucent,
57+
onPanStart: (details) {
58+
windowManager.startDragging();
59+
},
60+
onDoubleTap: maximizable
61+
? () async {
62+
bool isMaximized = await windowManager.isMaximized();
63+
if (!isMaximized) {
64+
windowManager.maximize();
65+
} else {
66+
windowManager.unmaximize();
67+
}
68+
}
69+
: null,
70+
child: child,
71+
);
72+
}
73+
}

sdk/python/packages/flet-core/src/flet_core/window_drag_area.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(
7171
visible: Optional[bool] = None,
7272
disabled: Optional[bool] = None,
7373
data: Any = None,
74+
maximizable: Optional[bool] = None,
7475
):
7576

7677
ConstrainedControl.__init__(
@@ -105,6 +106,7 @@ def __init__(
105106
self.__content: Optional[Control] = None
106107

107108
self.content = content
109+
self.maximizable = maximizable
108110

109111
def _get_control_name(self):
110112
return "windowDragArea"
@@ -124,3 +126,12 @@ def content(self):
124126
@content.setter
125127
def content(self, value):
126128
self.__content = value
129+
130+
# maximizable
131+
@property
132+
def maximizable(self) -> Optional[bool]:
133+
return self._get_attr("maximizable", data_type="bool", def_value=True)
134+
135+
@maximizable.setter
136+
def maximizable(self, value: Optional[bool]):
137+
self._set_attr("maximizable", value)

0 commit comments

Comments
 (0)