skip to Main Content

When using Windows_Manager and UI to make the app take the entire screen, I get the following error:

Invalid constant value.

Here is the code:

import 'dart:ui' as ui;
import 'package:window_manager/window_manager.dart';


void main() async {
  WidgetsFlutterBinding.ensureInitialized();
     Size logicalScreenSize = ui.window.physicalSize;
  WindowOptions windowOptions = const WindowOptions(
    size:  logicalScreenSize,                        //Error in this instruction
    center: true,
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
    titleBarStyle: TitleBarStyle.hidden,
  );
  windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.show();
    await windowManager.focus();
  });
  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  runApp(const MyApp());
}

I tried to combine most of the proposed solutions here but non of them works.

EDIT

The previous error has been resolved, but the app is still not taking the size of the screen!!

2

Answers


  1. So, the issue is, the logicalScreenSize variable is not constant means the the value will not be same that’s why you can’t assign that to const.

    As I can you’ve did this

    WindowOptions windowOptions = const WindowOptions(
        size:  logicalScreenSize,                        //Error in this instruction
        center: true,
        backgroundColor: Colors.transparent,
        skipTaskbar: false,
        titleBarStyle: TitleBarStyle.hidden,
        windowButtonVisibility: false,
      );
    

    Now you just need to delete const from first line

    WindowOptions windowOptions = WindowOptions(
    ....
    

    I removed const from WindowOptions

    SIZE NOT WORKING

    You need to assign minimumSize as well

    WindowOptions windowOptions = const WindowOptions(
    minimumSize: logicalScreenSize,
        .....
      );
    
    Login or Signup to reply.
  2. Remove this const and try and run

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search