Is there any way in Flutter to set the minimum window size for Windows?

387 views Asked by At

Many Windows programs allow you to reduce the window size up to a certain size. However, when I create a new project in Flutter, the window can be shrunk without any restrictions, so that nothing of the content is visible anymore. Is there any way to set this minimum size?

Until now I have done some unsuccessful research on the internet. The only thing I have managed to do is to read the current window size and then display a message if the window is too small instead of the actual window content. This is better than nothing, but still not what I want to do.

1

There are 1 answers

2
Texv On

A Container() widget has a parameter called constraints. With that you can set minimum and maximum sizes.

    final screenHeight = MediaQuery.of(context).size.height;
    final screenWidth = MediaQuery.of(context).size.width;

    Container(
      constraints: BoxConstraints(
        maxHeight: screenHeight,
        maxWidth:  screenWidth,
        minHeight: screenHeight * 0.5,
        minWidth: screenWidth * 0.5,
        ),
    );

You may also use a ConstrainedBox() widget instead of a Container().

ConstrainedBox(
    constraints: BoxConstraints(
      maxHeight: screenHeight,
      maxWidth:  screenWidth,
      minHeight: screenHeight * 0.5,
      minWidth: screenWidth * 0.5,
      ),
    ),