
Flutter and Firebase are both developed by Google, and they work together remarkably well. Firebase Hosting offers a fast global content delivery network, free SSL certificates, simple configuration, and a generous free tier, making it a natural home for Flutter web applications. Beyond hosting, Firebase provides authentication, databases, cloud functions, analytics, and storage, so you can build and run a complete product within one ecosystem. This tutorial explains how to deploy a Flutter web app on Firebase from scratch, including initial setup, configuration, deployment, preview channels, automated workflows, and custom domains.
How AAMAX.CO Helps Launch Firebase-Powered Applications
Firebase makes deployment easy, but building a complete, well-architected product still requires expertise. AAMAX.CO is a full-service digital marketing company offering web development, digital marketing, and SEO services worldwide. Their developers help businesses design application architecture, integrate cloud services, secure data with proper rules, and optimize performance for real users. They also provide marketing and SEO support to help applications attract and retain audiences after launch. Companies seeking reliable web application development can count on them to deliver scalable products built on modern platforms.
Prerequisites
Before starting, make sure you have:
- The Flutter SDK installed with web support enabled.
- Node.js installed, which is required for the Firebase CLI.
- A Google account to access the Firebase console.
- A Flutter project that runs correctly in Chrome.
Step 1: Create a Firebase Project
Go to the Firebase console and click to add a new project. Give it a descriptive name, choose whether to enable Google Analytics, and complete the setup. Once the project is created, you can register a web app inside it if you plan to use Firebase services like Authentication or Firestore. For hosting alone, the project itself is enough.
Step 2: Install the Firebase CLI
Install the Firebase command-line tools globally using npm with the command npm install -g firebase-tools. Then run firebase login to authenticate with your Google account in the browser. Verify the installation by running firebase projects:list, which should display the project you just created.
Step 3: Connect Firebase Services to Flutter (Optional)
If your app uses Firebase features, install the FlutterFire CLI with dart pub global activate flutterfire_cli and run flutterfire configure in your project directory. This generates a firebase_options.dart file containing configuration for each platform. Initialize Firebase in your main function before calling runApp. This step is not required for hosting but is essential for using Firebase backend services.
Step 4: Build the Flutter Web App
Create a production build with flutter build web --release. The compiled output is placed in the build/web directory. Confirm that the folder contains index.html, main.dart.js, and the assets directory. This folder is what Firebase Hosting will serve.
Step 5: Initialize Firebase Hosting
From the root of your Flutter project, run firebase init hosting. The CLI will ask several questions:
- Select a project: Choose the Firebase project you created.
- Public directory: Enter build/web.
- Configure as a single-page app: Answer yes so all routes rewrite to index.html.
- Set up automatic builds with GitHub: Optional, and covered below.
- Overwrite index.html: Answer no to keep Flutter's generated file.
This creates a firebase.json configuration file and a .firebaserc file that links your directory to the project.
Step 6: Deploy
Run firebase deploy --only hosting. Within moments, the CLI uploads your files and displays a hosting URL ending in web.app or firebaseapp.com. Open it in your browser to see your live Flutter app. Each subsequent deployment follows the same simple process: build, then deploy.
Step 7: Use Preview Channels for Testing
Firebase Hosting supports preview channels, which are temporary URLs for testing changes before they go live. Run firebase hosting:channel:deploy feature-name to create a shareable preview. This is ideal for client reviews and QA testing. Preview channels expire automatically after a configurable period, keeping your project tidy.
Step 8: Automate with GitHub Actions
Firebase can generate GitHub Actions workflows for you. During firebase init hosting, choose to set up GitHub integration, or run firebase init hosting:github later. Firebase will create workflows that deploy to a preview channel for pull requests and to production when changes merge into your main branch. Edit the workflow to install Flutter and run the build command before the deploy step, since the default template assumes a Node.js project.
Step 9: Configure Caching Headers
To ensure users receive updates promptly, add headers in firebase.json. Set Cache-Control to no-cache for index.html and the Flutter service worker file, while allowing long-term caching for hashed JavaScript, fonts, and images. Firebase applies compression automatically, so files are delivered efficiently without extra configuration.
Step 10: Add a Custom Domain
In the Firebase console, navigate to Hosting and click to add a custom domain. Firebase will ask you to verify ownership by adding a TXT record to your DNS settings, then provide A records to point your domain to Firebase servers. After DNS propagates, Firebase provisions a free SSL certificate automatically. You can connect both the apex domain and the www subdomain and redirect one to the other.
Troubleshooting Tips
If your deployed app shows the default Firebase welcome page, you likely allowed the CLI to overwrite index.html or set the wrong public directory. Rebuild and redeploy. If routes return errors on refresh, confirm that firebase.json contains a rewrite sending all paths to /index.html. For a blank screen, check the base href and browser console for missing files.
Conclusion
Firebase Hosting is one of the simplest and most powerful ways to deploy a Flutter web app. By creating a project, installing the CLI, building your app, initializing hosting with the correct settings, and deploying, you can go live in minutes. Add preview channels, automated workflows, smart caching, and a custom domain, and you have a professional, scalable hosting setup that grows with your application.