Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ English | [简体中文](README_zh.md)
+ Methods to get and set the positions of the window’s standard window buttons (such as the close, miniaturize, and zoom buttons).
+ Methods to control whether the window should be closable by the user, as well as methods to close the window programmatically.
+ Widgets to enable passthrough views in the toolbar that pass mouse events (such as clicking or dragging) to the Flutter application.
+ Methods to set min/max window size

Additionally, the package ships with an example project that showcases the plugin's features via an intuitive searchable user interface:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,16 @@ class CommandListProvider {
'momentarily highlighting the button and then closing the window.',
function: () => WindowManipulator.performClose(),
),
Command(
name: 'setWindowMinSize()',
description: 'Sets the minimum window size to 480x320.',
function: () => WindowManipulator.setWindowMinSize(const Size(480, 320)),
),
Command(
name: 'setWindowMaxSize()',
description: 'Sets the maximum window size to 960x640.',
function: () => WindowManipulator.setWindowMaxSize(const Size(960, 640)),
),
];
}
}
18 changes: 18 additions & 0 deletions lib/window_manipulator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,22 @@ class WindowManipulator {
},
);
}

/// Sets the minimum size for the window
static Future<void> setWindowMinSize(Size size) async {
await _completer.future;
await _windowManipulatorMethodChannel.invokeMethod('setWindowMinSize', {
'width': size.width,
'height': size.height,
});
}

/// Sets the maximum size for the window
static Future<void> setWindowMaxSize(Size size) async {
await _completer.future;
await _windowManipulatorMethodChannel.invokeMethod('setWindowMaxSize', {
'width': size.width,
'height': size.height,
});
}
}
16 changes: 16 additions & 0 deletions macos/Classes/MacOSWindowUtilsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,23 @@ public class MacOSWindowUtilsPlugin: NSObject, FlutterPlugin {
MainFlutterWindowManipulator.removeToolbarPassthroughView(id: id)
result(true)
break

case "setWindowMinSize":
let width = args["width"] as! CGFloat
let height = args["height"] as! CGFloat

MainFlutterWindowManipulator.setWindowMinSize(width: width, height: height)
result(true)
break

case "setWindowMaxSize":
let width = args["width"] as! CGFloat
let height = args["height"] as! CGFloat

MainFlutterWindowManipulator.setWindowMaxSize(width: width, height: height)
result(true)
break

default:
result(FlutterMethodNotImplemented)
break
Expand Down
16 changes: 16 additions & 0 deletions macos/Classes/MainFlutterWindowManipulator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -778,4 +778,20 @@ public class MainFlutterWindowManipulator {

passthroughViewHandler.removeToolbarPassthroughView(id: id)
}

public static func setWindowMinSize(width: CGFloat, height: CGFloat) {
if (self.mainFlutterWindow == nil) {
start(mainFlutterWindow: nil)
}

mainFlutterWindow!.minSize = NSMakeSize(width, height)
}

public static func setWindowMaxSize(width: CGFloat, height: CGFloat) {
if (self.mainFlutterWindow == nil) {
start(mainFlutterWindow: nil)
}

mainFlutterWindow!.maxSize = NSMakeSize(width, height)
}
}