3

Running flutter build web creates index.html file in /build/web/ along with

assets                    icons                     manifest.json
favicon.png               index.html                version.json
flutter_service_worker.js main.dart.js

The current flutter channel is beta.

$ flutter channel

Flutter channels:  
  master  
  dev  
* beta  
  stable

flutter --version

Flutter 1.25.0-8.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 8f89f6505b (2 weeks ago) • 2020-12-15 15:07:52 -0800
Engine • revision 92ae191c17
Tools • Dart 2.12.0 (build 2.12.0-133.2.beta)

When I try to open /build/web/index.html in the Chrome browser, it shows blank. Is it usual or do I need to install any node packages to make it run?

Note: I followed this doc https://flutter.dev/docs/get-started/web.

Does it have anything to do with this code in index.html which does not seem to be included in the earlier flutter versions?

  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    Fore more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

3 Answers3

12

you need to install node.js server from npm to run the website on.

npm install -g http-server

Change directory to /build/web and run the server on localhost with:

npx http-server
Calvin Gonsalves
  • 1,738
  • 11
  • 15
  • 1
  • @SawThinkarNayHtoo np :) – Calvin Gonsalves Jan 12 '21 at 02:39
  • Hey I hav a issue actually I started server on local host and then I am unable to exit my project from there know i am panicking I am afraid because of hackers and stealers I hav no idea in this area I unfortunately closed the terminal so I am unable to control + c and I don't know how many host are running and how please help me. Asap –  Mar 15 '21 at 20:51
  • @Lucian closing the terminal stops the http server i guess. You can try solutions suggested in https://stackoverflow.com/questions/14790910/stop-all-instances-of-node-js-server – Calvin Gonsalves Mar 16 '21 at 21:10
6

Adding to the topic, you can also use python to server it: Set up a local testing server

\[flutter_project]\build\web> python -m http.server

or

\[flutter_project]\build\web> python -m SimpleHTTPServer

Then go to localhost:8000

Jonas Cerqueira
  • 160
  • 2
  • 8
2

For me this worked:

  1. Download Python from python.org and install it.
  2. Open command prompt and type your build/web path like this: cd C:\Users\YourUSER\Documents\build\web
  3. Type python -m http.server 8080 -> This is another port exclusively for your app.
  4. Open Edge Browser and type: http://localhost:8080
  5. Click on the icon button on top right (install yourApp to run on your own page) And thats it! You can create a shortcut on your desktop to run automatically!
LW001
  • 2,452
  • 6
  • 27
  • 36