英文:
Start Flutter Desktop In The Size Of Screen
问题
在使用 Windows_Manager 和 UI 使应用程序占据整个屏幕时,我收到以下错误:
无效的常量值。
以下是代码:
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
然后尝试运行。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论