我刚刚在Windows上创建了一个flutter项目
flutter create appname --platforms=windows,macos
现在我可以启动这个Windows应用程序
flutter run -d windows
一切都很完美。但问题是我无法在发布模式下启动Windows应用程序。我试过:
flutter run --release -d windows
但是应用程序窗口没有显示。我只看到任务管理器中运行的进程。没有必要向您显示项目的代码,因为它是您使用flutter create
获得的模板项目。没有修改单行。
发布模式适用于所有其他平台,包括web和macos。我也尝试手动启动.exe
文件,但也不起作用。我也尝试更改为flutter的主版本,但它也不适用于最新的主版本。flutter doctor -v
没有显示任何错误:
[✓] Flutter (Channel master, 3.9.0-17.0.pre.7, on Microsoft Windows [Version 10.0.22621.1413], locale de-DE)
• Flutter version 3.9.0-17.0.pre.7 on channel master at C:\Program Files\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 785ea2a4c9 (2 hours ago), 2023-03-24 13:01:07 -0400
• Engine revision 7b91f9d08f
• Dart version 3.0.0 (build 3.0.0-365.0.dev)
• DevTools version 2.22.2
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\User\AppData\Local\Android\sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.3)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.5.33516.290
• Windows 10 SDK version 10.0.22621.0
[✓] Android Studio (version 4.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.2
• Flutter plugin version 58.0.3
• Dart plugin version 211.7665
[✓] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.1413]
• Chrome (web) • chrome • web-javascript • Google Chrome 111.0.5563.111
• Edge (web) • edge • web-javascript • Microsoft Edge 111.0.1661.51
[✓] Network resources
• All expected network resources are available.
• No issues found!
2条答案
按热度按时间yqkkidmi1#
看起来这是Flutter的一个bug?
编辑
windows/runner/flutter_window.cpp
,替换此行:用这个:
来源。
xhv8bpkk2#
如果你像@Zensonaton的回答中提到的那样编辑
windows/runner/flutter_window.cpp
,它就可以工作。但是我通过在MaterialApp
中添加restorationScopeId
来修复它,如下所示: