Home > Software design >  flutter: set exact width and height of the app's screen and restrict user ability to resize the
flutter: set exact width and height of the app's screen and restrict user ability to resize the

Time:12-18

I want to create a flutter desktop app that has an exact width and height for the app's screen. So for example if width = 400 and height=800, then the app's screen stay 400x800.

I would also like to restrict the user from resizing the screen.

CodePudding user response:

Add to your dependencies:

window_size:
    git:
      url: https://github.com/google/flutter-desktop-embedding
      path: plugins/window_size

Inside your main.cpp file find and change the Window size to:

Win32Window::Size size(400, 800);

And change your main to:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
    const mySize = Size(400, 800);
    setWindowMaxSize(mySize);
    setWindowMinSize(mySize);
  }
  runApp(const MyApp());
}

You would need to import 'dart:io' to access Platform and

import 'package:window_size/window_size.dart' to access setWindowMaxSize and setWindowMinSize

  • Related