flutterproject-idx

How to run Flutter web with IDX


(copy of bug in IDX)

I opened a flutter web app from GitHub in IDX.

There is folder 'website' that contains the Flutter package.

When I run flutter run -d chrome, I get this:

No supported devices found with name or id matching 'chrome'.

The following devices were found:
Android SDK built for x86 (mobile) • emulator-5554  • android-x86 • Android 10 (API 29) (emulator)
Android SDK built for x86 (mobile) • localhost:5555 • android-x86 • Android 10 (API 29) (emulator)
Linux (desktop)                    • linux          • linux-x64   • IDX GNU/Linux 6.1.85+

I tried to follow this steps, but with no success. I am not sure how 'npm run' is going to start a flutter web app. It at least want to (1) build the app for web and (2) navigate to 'website/build/web', and I do not see it in the script.

Is it possible to run Flutter for web from IDX?

In fact, my projects contains VSCode configuration, that defines how to run them. And, as IDX is a flavor of VSCode, I expected this configuration to just work. But it does not seem to be picked up.


Solution

  • Solved this by adding the file .idx/dev.nix with content:

    { pkgs, ... }: {
      idx.previews = {
        enable = true;
        previews = {
          web = {
            command = ["flutter" "run" "--machine" "-d" "web-server" "--web-hostname" "0.0.0.0" "--web-port" "$PORT"];
            cwd = "website";
            manager = "flutter";
          };
        };
      };
    }
    

    Great thanks to IDX support!