Simple instructions to deploy your Flutter web app to GitHub Pages.
- Flutter SDK installed
- Git repository on GitHub
- GitHub account
flutter build web --releaseThis creates optimized web files in the build/web/ directory.
GitHub Pages serves files from the docs/ folder or a gh-pages branch. We'll use the docs/ folder method:
# Create docs directory
mkdir docs
# Copy built files to docs
cp -r build/web/* docs/
# Add docs to git
git add docs/
git commit -m "Add web build for GitHub Pages"
git push origin main- Go to your GitHub repository
- Click Settings tab
- Scroll down to Pages section
- Under Source, select Deploy from a branch
- Choose main branch and /docs folder
- Click Save
Your app will be available at:
https://yourusername.github.io/web_querystring_semantics/
Once deployed, test these URLs:
https://yourusername.github.io/web_querystring_semantics/https://yourusername.github.io/web_querystring_semantics/?enableSemantics=truehttps://yourusername.github.io/web_querystring_semantics/?enableSemantics=falsehttps://yourusername.github.io/web_querystring_semantics/?enableSemantics=True
For automatic deployment on every push, create .github/workflows/deploy.yml:
name: Deploy to GitHub Pages
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.9.2'
- run: flutter pub get
- run: flutter build web --release
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/webThen change GitHub Pages source to Deploy from a branch → gh-pages.
- 404 Error: Make sure GitHub Pages is enabled and pointing to
/docsfolder - Build Issues: Run
flutter cleanthenflutter build web --release - Caching: GitHub Pages may take a few minutes to update after pushing changes
When you make changes to your app:
# Build new version
flutter build web --release
# Copy to docs
cp -r build/web/* docs/
# Commit and push
git add docs/
git commit -m "Update web build"
git push origin mainThat's it! Your Flutter web app is now live on GitHub Pages.