Search code examples
goflutter-web

Flutter web with Golang Server


Is it possible to run flutter web build using golang server? Golang has facility to serve html file and flutter web gives output as index.html and js files. if it is possible then how golang code should look like?


Solution

  • as the friendly doc mentions it, i believe you got to build your app.

    https://flutter.dev/docs/get-started/web#build

    Run the following command to generate a release build:

    flutter build web
    

    This populates a build/web directory with built files, including an assets directory, which need to be served together.

    how golang code should look like?

    like any other regular HTTP golang server.

    http.Handle("/build/web/", http.StripPrefix("/build/web/", http.FileServer(http.Dir("build/web"))))
    
    http.ListenAndServe(":8080", nil)