N90J
N90J

Reputation: 67

Is it possible to limit resizing the width and height of an app with Flutter?

So I looked into constraints in general, but I couldn't find such a thing. What I want is that on a macOs app for example, someone would be only able to resize the window of the application up to the limits set by the app (e.g. 500px by 500px). This would then also prevent any overflow issues with certain widgets that you just don't want people to see when they are smaller than a certain size.

Also I looked at desktop_window:

Future _getWindowSize() async {
    // var size = await DesktopWindow.getWindowSize();
    setState(() async {
      await DesktopWindow.setMinWindowSize(Size(1000, 500));
      await DesktopWindow.setMaxWindowSize(Size(1200, 800));
    });
  }

but that just sets some initial values and I can still adjust it to my liking, so it doesn't really help. And yes I understand I can work with MediaSize queries, to make things disappear or make it look different, but I don't really want that.

If something exists in Flutter to do the above, it'd be really helpful to know!

Upvotes: 1

Views: 1159

Answers (2)

N90J
N90J

Reputation: 67

Actually, it worked with desktop_window package. I tried it with a simple example (i.e. by pressing a button to set it).

See their examples on github: https://pub.dev/packages/desktop_window/example

Upvotes: 1

omar hatem
omar hatem

Reputation: 1989

you can wrap your app in a ConstrainedBox and give it the constraints you want

runApp(
      Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(maxWidth: 1000, minWidth: 500, maxHeight: 1000, minHeight: 500),
          child: MyApp(),
        ),
      ),
    );

Upvotes: 0

Related Questions