macosui / macos_window_utils.dart

macos_window_utils is a Flutter package that provides a set of methods for modifying the NSWindow of a Flutter application on macOS.
https://pub.dev/packages/macos_window_utils
MIT License
49 stars 9 forks source link

Doesn't set MediaQueryData.viewPadding #50

Open kerberjg opened 1 month ago

kerberjg commented 1 month ago

When using macos_window_utils in combination with other UI libraries like Material and Cupertino, the content tends to invade the button area, like this:

image

The simple solution would be to set the viewPadding property on MediaQuery, which is how Flutter compensates for notches on phones. Here's my temporary workaround:

if(defaultTargetPlatform == TargetPlatform.macOS) {
      return MediaQuery(
        child: app,
        data: MediaQuery.of(context).copyWith(
          padding: const EdgeInsets.only(top: 40),
        ),
      );
    }

Works as intended:

image

Adrian-Samoticha commented 1 month ago

macos_window_utils provides a TitlebarSafeArea class specifically for this purpose.

kerberjg commented 1 month ago

@Adrian-Samoticha That does not yield the intended result.

return TitlebarSafeArea(
  child: app
);
image

In Flutter, SafeArea is used to wrap the content of a page, not the page scaffold itself. If the MediaQueryData.padding property had been set properly, there wouldn't be a need for a separate TitlebarSafeArea widget, as the vanilla SafeArea widget pulls information from MediaQueryData.padding, as do the various AppBar widgets in all design libraries.

The ideal solution would be something like WindowManipulator.getMediaQueryData that will return the MediaQueryData object with the proper padding (and other properties, as needed) set, in addition to documentation so users know when/how to use it.

I'd be happy to contribute any of the above improvements if they sound good

Adrian-Samoticha commented 1 month ago

If the TitlebarSafeArea doesn’t fit your use case and you’d like to construct a MediaQueryData with the appropriate padding, you can use the WindowManipulator.getTitlebarHeight() method to get the height of the title bar.

kerberjg commented 1 month ago

That is what I'm currently doing, however I was suggesting that perhaps this is functionality that the library should provide out-of-the-box, since without it most Cupertino/Material apps will look & behave improperly

Adrian-Samoticha commented 2 weeks ago

I don’t really think that’s necessary. Since macos_window_utils provides only a single property that’s in any way related to MediaQuery, it wouldn’t really make much sense to abstract that away. Also, if you’re trying to create an app that looks like a native macOS app, you should probably check out macos_ui instead of using Flutter’s built-in Cupertino widgets.