Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      The Double-Edged Sustainability Sword Of AI In Web Design

      August 20, 2025

      Top 12 Reasons Enterprises Choose Node.js Development Services for Scalable Growth

      August 20, 2025

      GitHub’s coding agent can now be launched from anywhere on platform using new Agents panel

      August 20, 2025

      Stop writing tests: Automate fully with Generative AI

      August 19, 2025

      I’m a diehard Pixel fan, but I’m not upgrading to the Pixel 10. Here’s why

      August 21, 2025

      Google Pixel Watch 4 vs. Samsung Galaxy Watch 8: I compared the two best Androids, and here’s the winner

      August 21, 2025

      Get a free Amazon gift card up to $300 when you preorder a new Google Pixel 10 phone – here’s how

      August 21, 2025

      Everything announced at Made by Google 2025: Pixel 10 Pro, Fold, Watch 4, and more

      August 21, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Copy Errors as Markdown to Share With AI in Laravel 12.25

      August 21, 2025
      Recent

      Copy Errors as Markdown to Share With AI in Laravel 12.25

      August 21, 2025

      Deconstructing the Request Lifecycle in Sitecore Headless – Part 2: SSG and ISR Modes in Next.js

      August 20, 2025

      Susan Etlinger, AI Analyst and Industry Watcher on Building Trust

      August 20, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      TerraMaster D1 SSD Plus Review: Experience a Faster External SSD

      August 20, 2025
      Recent

      TerraMaster D1 SSD Plus Review: Experience a Faster External SSD

      August 20, 2025

      Microsoft is investigating Windows 11 KB5063878 SSD data corruption/failure issue

      August 20, 2025

      Microsoft Surface Won’t Turn On: 6 Tested Solutions to Fix

      August 20, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to Deploy a Flutter Web App to Firebase Hosting with GitHub Actions

    How to Deploy a Flutter Web App to Firebase Hosting with GitHub Actions

    August 20, 2025

    Deploying a Flutter web app can feel repetitive if you’re doing it manually every time. GitHub Actions automates this by continuously deploying your app to Firebase Hosting whenever you push code to your repository.

    This guide walks you through setting up Firebase Hosting, configuring GitHub Actions, and managing deployments. By the end, you’ll have a reliable CI/CD pipeline for your Flutter web project.

    Table of Contents:

    1. Prerequisites

    2. Step 1: Set Up Firebase Hosting

      • Initialize Firebase in Your Project
    3. Step 2: Configure Firebase Hosting

      • Explanation:
    4. Step 3: Add Firebase Config to Flutter

      • Explanation:
    5. Step 4: Configure GitHub Actions

      • Explanation of Steps:
    6. Step 5: Set Up Firebase Token

    7. Step 6: Validate & Monitor Deployment

    8. Advanced Configurations

      • Custom Build

      • Multiple Environments (Staging & Production)

      • Cache Dependencies (Speed up builds)

    9. Troubleshooting

    Prerequisites

    Before diving in, make sure you have these ready:

    1. Flutter Installed: You can install Flutter from flutter.dev, then confirm installation with:

    flutter --version
    

    2. Firebase CLI Installed: The Firebase CLI lets you interact with Firebase Hosting. Install it via npm like this:

    npm install -g firebase-tools
    

    Check installation with:

    firebase --version
    

    3. A GitHub Repository: Your Flutter project should be pushed to GitHub.

    4. Firebase Project Created: Go to Firebase Console, create a project, and enable Firebase Hosting.

    Step 1: Set Up Firebase Hosting

    Initialize Firebase in Your Project

    Open your terminal and navigate to your project:

    cd path/to/your/flutter/project
    

    Initialize Firebase Hosting:

    firebase init
    

    During setup, you’ll need to provide some information:

    1. Hosting: Select Firebase Hosting.

    2. Public Directory: Enter build/web (this is where Flutter outputs web builds).

    3. Single-Page App: Select Yes (rewrites all routes to /index.html).

    4. Automatic Builds: You can skip since we’ll configure GitHub Actions manually.

    Step 2: Configure Firebase Hosting

    A file called firebase.json will be created. Ensure it looks like this:

    {
      "hosting": {
        "public": "build/web",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ]
      }
    }
    
    1. hosting.public tells Firebase where to find your built app (build/web).

    2. ignore files Firebase should not upload (hidden files, config files, node_modules).

    You may also see a .firebaserc file for project aliasing:

    {
      "projects": {
        "default": "your-project-id"
      }
    }
    

    This links your local project to your Firebase project ID.

    Step 3: Add Firebase Config to Flutter

    When you connect Firebase to Flutter (via the flutterfire CLI), it generates a file like firebase_options.dart.

    In your main.dart, initialize Firebase:

    import 'package:flutter/material.dart';
    import 'package:firebase_core/firebase_core.dart';
    import 'firebase_options.dart';
    
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      runApp(MyApp());
    }
    
    1. WidgetsFlutterBinding.ensureInitialized() ensures that the Flutter engine is ready before Firebase initializes.

    2. Firebase.initializeApp() connects your app to Firebase using the auto-generated options.

    Step 4: Configure GitHub Actions

    We’ll now create a workflow that automatically builds and deploys your Flutter web app.

    Create a file in your repo: .github/workflows/firebase-hosting.yml

    name: Deploy to Firebase Hosting
    
    on:
      push:
        branches:
          - main  # Deploy only when code is pushed to main
      pull_request:
        branches:
          - main
    
    jobs:
      build_and_deploy:
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout Repository
          uses: actions/checkout@v2
    
        - name: Set up Flutter
          uses: subosito/flutter-action@v3
          with:
            flutter-version: '3.24.1'
    
        - name: Install Dependencies
          run: flutter pub get
    
        - name: Build Flutter Web
          run: flutter build web --release
    
        - name: Set up Node.js
          uses: actions/setup-node@v3
          with:
            node-version: '18'
    
        - name: Install Firebase CLI
          run: npm install -g firebase-tools
    
        - name: Deploy to Firebase Hosting
          run: firebase deploy --only hosting --project <firebase-project-id>
          env:
            FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
    

    Here’s what’s going on in this code:

    1. Checkout Repository: Pulls your code into the runner.

    2. Set up Flutter: Installs the specified Flutter version.

    3. Install Dependencies: Runs flutter pub get.

    4. Build Flutter Web: Builds the release version of your web app.

    5. Set up Node.js: Needed for Firebase CLI.

    6. Install Firebase CLI: Installs Firebase deploy tool.

    7. Deploy to Firebase Hosting: Deploys the built files to Firebase.

    Step 5: Set Up Firebase Token

    GitHub needs a token to authenticate with Firebase.

    Run this locally:

    firebase login:ci
    

    Then copy the token shown.

    Next, go to your GitHub Repository → Settings → Secrets and Variables → Actions.

    Create a new secret named: FIREBASE_TOKEN and paste in the token you copied. This keeps your credentials safe.

    Step 6: Validate & Monitor Deployment

    Commit the workflow file like this:

    git add .github/workflows/firebase-hosting.yml
    git commit -m "Setup GitHub Actions for Firebase Hosting"
    git push origin main
    

    Go to your GitHub repo, select the Actions tab, and then watch the workflow run. You will see an interface that looks like these images:

    work flow in running in progress

    work flow completed

    Once it’s successful, go to:

    https://your-project-id.web.app

    https://your-project-id.firebaseapp.com

    Advanced Configurations

    Custom Build

    If you need a specific renderer (for example, HTML instead of CanvasKit):

    run: flutter build web --release --web-renderer html
    

    Multiple Environments (Staging & Production)

    run: firebase deploy --only hosting --project ${{ secrets.FIREBASE_PROJECT }}
    

    Define FIREBASE_PROJECT as a secret for each environment.

    Cache Dependencies (Speed up builds)

    - name: Cache Flutter Dependencies
      uses: actions/cache@v3
      with:
        path: ~/.pub-cache
        key: ${{ runner.os }}-pub-cache-${{ github.sha }}
        restore-keys: |
          ${{ runner.os }}-pub-cache-
    

    Troubleshooting

    You might encounter a few common issues. Her are some quick fixes to help you deal with them:

    IssueFix
    No active projectRun firebase use --add locally and check .firebaserc.
    Node.js version mismatchEnsure node-version: '18' in workflow.
    Firebase CLI errorsReinstall with npm install -g firebase-tools.
    Deprecated warnings in index.htmlUpdate to latest Flutter web template.

    Wrapping Up

    By integrating Firebase Hosting with GitHub Actions, you now have a CI/CD pipeline for your Flutter web app.

    Every push to main automatically triggers a build and deploy, keeping your app live with zero manual effort.

    To dive deeper, check:

    1. Flutter Web Docs

    2. Firebase Hosting Docs

    3. GitHub Actions Docs

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Build a Tic Tac Toe Game with Phaser.js
    Next Article Learn Key System Design Principles Behind High-Traffic Platforms Like Gaming and Job Discovery

    Related Posts

    Development

    Copy Errors as Markdown to Share With AI in Laravel 12.25

    August 21, 2025
    Artificial Intelligence

    Scaling Up Reinforcement Learning for Traffic Smoothing: A 100-AV Highway Deployment

    August 21, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Step-by-Step Guide to Build a Customizable Multi-Tool AI Agent with LangGraph and Claude for Dynamic Agent Creation

    Machine Learning

    CVE-2025-51054 – Vedo Suite Authentication Bypass

    Common Vulnerabilities and Exposures (CVEs)

    CISA Issues Warning on Commvault Web Server Flaw Exploited in the Wild

    Security

    Hazy Hawk Exploits DNS Records to Hijack CDC, Corporate Domains for Malware Delivery

    Development

    Highlights

    Linux

    4 Critical Security Flaws Patched in VMware Workstation Pro

    July 18, 2025

    Virtualisation choices on Linux are, as I’m sure you’re know, varied – even more so…

    Citrix Bleed 2 flaw now believed to be exploited in attacks

    June 27, 2025

    KDE Plasma 6.4 su Arch Linux: Necessaria l’Installazione Manuale di Pacchetti

    June 21, 2025

    BreachForums broken up? French police arrest five members of notorious cybercrime site

    June 28, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.