Closed cbenhagen closed 9 months ago
On this topic, I recently got a pretty solid "universal" drag going, using the window_size plugin (which supports all 3 desktop platforms).
This is some ugly code, and it's not quite perfect (dragging is not 1:1, more like 1:0.99), but it's really close:
onPointerMove: (d) async {
if (_ignoreNext) {
// Have to skip each 2nd event, cause flutter generates one when we move
_ignoreNext = false;
return;
}
_windowPos += d.delta * 2; // Note sure why we need to double this, but it gets us real close
Window.setWindowFrame(_windowPos & _windowSize);
_ignoreNext = true;
},
// Also called on each build:
void _updateWindowSize() async => _windowSize = (await Window.getWindowInfo()).frame.size;
Seems like there might be some opportunity to build on the base API's from WindowSize, and just add on what is really unique to this package (prefab'd Windows btns, maximize/minimize methods, and ability to hide native title bar). Though I think max/min probably best belong in the core as well, maybe we can try and land a PR for that.
We had to remove BitDojo for now just cause it prevents us from building on Web, but luckily this works ok across all platforms.
Haven't had the chance to test this on a non-retina screen but I guess you'd might want to do:
_windowPos += d.delta * MediaQuery.of(context).devicePixelRatio;
Related issue: https://github.com/flutter/flutter/issues/71680
With regards to dragging, isn't the MoveWindow
widget enough for your use case @esDotDev ?
There is a (semi-) official plugin with very similar functionality at https://github.com/google/flutter-desktop-embedding/tree/master/plugins/window_size. It would be nice to describe what sets this plugin apart. Maybe the two could be merged?