skip to Main Content

I just created a flutter project on Windows with

flutter create appname --platforms=windows,macos

Now I can start this Windows app with

flutter run -d windows

and everything works perfectly.
But the problem is that I can not start the Windows app in release mode. I tried:

flutter run --release -d windows

but the app window is not showing up. I just see the process running in the task manager. There is no need to show you the code of the project as it is the template project you get with flutter create. No single line was modified.

The release mode works on every other platforms including web and macos. I also tried to start the .exe file manually but that doesn’t work either. I also tried changing to the master version of flutter but it also does not work with the latest master version.

flutter doctor -v does not show any errors:

[✓] 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 Filesflutter
    • 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:UsersUserAppDataLocalAndroidsdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:Program FilesAndroidAndroid Studiojrebinjava
    • 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 FilesGoogleChromeApplicationchrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.3)
    • Visual Studio at C:Program FilesMicrosoft Visual Studio2022Community
    • 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 FilesAndroidAndroid 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 FilesJetBrainsIntelliJ 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

Answers


  1. Chosen as BEST ANSWER

    It works if you edit the windows/runner/flutter_window.cpp like mentioned in @Zensonaton's answer. But I fixed it by adding a restorationScopeId in MaterialApp like this:

    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          restorationScopeId: "Test", // <-- Add this line
          home: Scaffold(
            body: Container()
          )
        );
      }
    }
    

  2. Looks like this is a bug with Flutter?

    Edit the windows/runner/flutter_window.cpp, replace this line:

    flutter_controller_->engine()->SetNextFrameCallback([&]() {
        this->Show();
    });
    

    with this:

    this->Show();
    

    Source.

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