开始Flutter桌面以屏幕大小开始。

huangapple go评论59阅读模式
英文:

Start Flutter Desktop In The Size Of Screen

问题

在使用 Windows_ManagerUI 使应用程序占据整个屏幕时,我收到以下错误:

无效的常量值。

以下是代码:

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,                        // 此指令中的错误
    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());
}

编辑

先前的错误已解决,但应用程序仍然未占据整个屏幕大小!

英文:

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!!

答案1

得分: 1

以下是翻译好的部分:

问题是,logicalScreenSize 变量不是常数,意味着其值不会相同,因此无法将其分配为常数。

正如我所看到的:

WindowOptions windowOptions = const WindowOptions(
    size:  logicalScreenSize,                        // 这一行有错误
    center: true,
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
    titleBarStyle: TitleBarStyle.hidden,
    windowButtonVisibility: false,
);

现在你只需要从第一行删除 const

WindowOptions windowOptions = WindowOptions(
....

我从 WindowOptions 中移除了 const

尺寸不起作用

你还需要分配 minimumSize

WindowOptions windowOptions = const WindowOptions(
minimumSize: logicalScreenSize,
    ....
  );
英文:

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,
    .....
  );

答案2

得分: -1

移除这个 const 然后尝试运行。

英文:

Remove this const and try and run

开始Flutter桌面以屏幕大小开始。

huangapple
  • 本文由 发表于 2023年4月10日 21:07:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977404.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定