Deploy Flutter web app with GitHub Actions or GitLab CI/CD on Pages in 5 min

Flutter is growing in its popularity from day to day, and now it is even easier to spin it off with web support. Probably the quickest way to see web in action is to deploy it on GitLab pages or GitHub pages. Lets see how to do this in 5 minutes

Create a Flutter app

First step is to create a Flutter project. Since 2.0 web support is native, so we just need to use latest stable version:

Update base URL

Assuming that your future repository name will be flutter_web lets update the base URL for correct routing. Open web/index.html and update:

This steps are common for both GitLab & Github platforms.

GitHub

Create an empty project on the GitHub.

Please, note that your Repository name should be the same as a base URL we updated above

GitHub Actions

Now let’s add a GitHub actions script. Create a new file: .github/workflows/build-deploy.yml with a next content:

After merging this to master GitHub automatically recognises a new action and triggers a build

Wait utill pipeline successfully passes

This action will create a new branch gh-pages where you can check out content of the web build

GitHub Pages

Last step is to enable GitHub Pages for this repo from the Settings/Pages

GitHub Preview

Visit your pages URL to see deployed web-app

GitLab

Create an empty project on the GitLab.

Same as for GitHub, make sure that Project slug is the same as the base URL in web/index.html Flutter project

GitLab CI/CD

In the root folder create .gitlab-ci.yml file with the next content:

https://gitlab.com/-/snippets/2113393

GitLab CI/CD

As soon as you merge your changes to master , GitLab will automatically recognise CI/CD configuration and kick off a build

GitLab Pages

After pipeline succeeds visit Settings/Pages to find your project URL