12

I have tried flutter Windows Desktop application, but I am not able hide title bar to run app in full screen mode windows

Yuvaraj M
  • 129
  • 1
  • 4

7 Answers7

6

Got the same problem and I'm here to share my solution.

I'm not a Win32 developer but I managed to make a basic fullscreen this way.

This code works for my Flutter version 1.21.0-10.0.pre.114, I hope it will for you too.

My solution is heavily inspired by this one : https://stackoverflow.com/a/2416613/14093885

You have to edit ./windows/runner/main.cpp

Insert the following code between these statements around line 30:

window.SetQuitOnClose(true);

//Insert Code Here

run_loop.Run();

Code to insert :

//HWND is window handler
HWND hwnd = window.GetHandle(); 

auto windowHDC = GetDC(hwnd);
int fullscreenWidth  = GetDeviceCaps(windowHDC, DESKTOPHORZRES);
int fullscreenHeight = GetDeviceCaps(windowHDC, DESKTOPVERTRES);
int colourBits       = GetDeviceCaps(windowHDC, BITSPIXEL);
int refreshRate      = GetDeviceCaps(windowHDC, VREFRESH);

DEVMODE fullscreenSettings;
bool isChangeSuccessful;

EnumDisplaySettings(NULL, 0, &fullscreenSettings);
fullscreenSettings.dmPelsWidth        = fullscreenWidth;
fullscreenSettings.dmPelsHeight       = fullscreenHeight;
fullscreenSettings.dmBitsPerPel       = colourBits;
fullscreenSettings.dmDisplayFrequency = refreshRate;
fullscreenSettings.dmFields           = DM_PELSWIDTH |
                                      DM_PELSHEIGHT |
                                      DM_BITSPERPEL |
                                      DM_DISPLAYFREQUENCY;

SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, fullscreenWidth, fullscreenHeight, SWP_SHOWWINDOW);
isChangeSuccessful = ChangeDisplaySettings(&fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
ShowWindow(hwnd, SW_MAXIMIZE);

EDIT - Flutter 2:

According to @Pavel the last line ShowWindow(hwnd, SW_MAXIMIZE); is not needed in Flutter 2.

Luxariox
  • 359
  • 3
  • 10
  • The flutter emulator freezes when I try this. Are you sure it's just a matter of pasting that code in? – Tunnelvisie Mar 14 '21 at 12:14
  • I'm not sure about it depending on the version of flutter your using. If it's the one I was using that should work but I would not be surprised to learn that it changed with flutter 2.0. If you are using the good `window` that should be okay I think. Anyway I am not a win32 dev so if that's not it my method probably is outdated. – Luxariox Mar 15 '21 at 13:15
  • @Tunnelvisie if you are using Flutter 2, remove this line: `ShowWindow(hwnd, SW_MAXIMIZE);` – Pavel Jun 27 '21 at 15:29
4

I guess window_manager can achieve your needs

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  window_manager:
    git:
      url: https://github.com/leanflutter/window_manager.git
      ref: main

Usage


// Enter fullscreen
await WindowManager.instance.setFullScreen(true);
// Level fullscreen
await WindowManager.instance.setFullScreen(false);
lijy91
  • 136
  • 1
  • 3
1

There is no built-in support for full-screen mode yet, so there's no Dart API you can call to enter full screen. If you are familiar with Win32 programming, you could either change the Runner code directly to make the window full screen, or write a plug-in that does it.

smorgan
  • 18,340
  • 2
  • 42
  • 52
1

You need to implement the plugin window_size: https://github.com/google/flutter-desktop-embedding/tree/master/plugins/window_size

@override initState() {
super.initState();
Future.delayed(Duration.zero).then((finish) async {
  if (Platform.isMacOS) {
    // * FULL SCREEN
    PlatformWindow window = await getWindowInfo();
    setWindowFrame(Rect.fromLTWH(0, 0, window.screen.frame.width, window.screen.frame.height));
  }
});

}

Gonzalo Lopez
  • 67
  • 1
  • 5
  • 2
    That code will give you a decorated window that's the size of the screen. There will still be a title bar, resize handle, menu bar, etc. That's not the same as full screen mode. – smorgan Nov 30 '19 at 03:23
1

I think it must change the cpp file now.

win32_window.cpp replace "WS_OVERLAPPEDWINDOW" with "WS_POPUP | WS_MAXIMIZE"

/* WS_POPUP : without title bar WS_MAXIMIZE : full screen */

1

this is the link for more help window Size I have Done this in this way I get window size from here: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles

in flutter windows app for window size : go to windows/runner/win32_window.cpp

  • for fullscreen window without titlebar WS_POPUP | WS_VISIBLE
  • for fullscreen window with titlebar(without any icon such as close,minimize,restore,logo) WS_MAXIMIZE | WS_VISIBLE
  • for small or customized window WS_OVERLAPPEDWINDOW | WS_VISIBLE
  • for fullscreen window with titlebar WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE

Find this CODE given below in win32_window.cpp file and change as you wish.

HWND window = CreateWindow(
  window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE,
  Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
  Scale(size.width, scale_factor), Scale(size.height, scale_factor),
  nullptr, nullptr, GetModuleHandle(nullptr), this);
R.Raman
  • 51
  • 5
1

Use this package: https://github.com/leanflutter/window_manager

In your main, add this code after 'RunApp':

WidgetsFlutterBinding.ensureInitialized();
// Must add this line.
await windowManager.ensureInitialized();

// Use it only after calling `hiddenWindowAtLaunch`
windowManager.waitUntilReadyToShow().then((_) async {
// Hide window title bar
await windowManager.setTitleBarStyle('hidden');
await windowManager.setFullScreen(true);
await windowManager.center();
await windowManager.show();
await windowManager.setSkipTaskbar(false);
});
Matteo Toma
  • 308
  • 2
  • 10