
Firebase Hosting and Flutter are both Google technologies, and they work exceptionally well together. Firebase Hosting serves static content over a global CDN with automatic SSL, supports single-page app rewrites, offers preview channels for testing, and includes a free tier that suits many projects. If your Flutter app already uses Firebase services such as Authentication, Firestore, or Cloud Functions, hosting it on Firebase keeps everything in one ecosystem. This step-by-step guide walks through setting up, deploying, and maintaining a Flutter web app on Firebase Hosting.
How AAMAX.CO Helps Teams Launch on Firebase
Firebase makes deployment straightforward, but production apps still need careful configuration, security, and performance planning. AAMAX.CO is a full-service digital marketing company offering web development, digital marketing, and SEO services worldwide. Their web application development team builds Flutter and Firebase applications, configures hosting, security rules, custom domains, and CI/CD pipelines, and optimizes load times. Businesses can launch confidently knowing their app and its backend are configured correctly from the start.
Prerequisites
Before you begin, make sure you have:
- The Flutter SDK installed and web support enabled.
- A Google account and access to the Firebase console.
- Node.js installed, which is required for the Firebase CLI.
- A Flutter project that runs successfully with
flutter run -d chrome.
Step 1: Create a Firebase Project
Open the Firebase console and create a new project or select an existing one. If your app uses other Firebase services, register a web app within the project to obtain its configuration. Using the FlutterFire CLI with flutterfire configure can generate the configuration file for your Flutter project automatically.
Step 2: Install and Log In to the Firebase CLI
Install the Firebase command-line tools globally using npm with npm install -g firebase-tools. Then authenticate with firebase login, which opens a browser window to sign in with your Google account. Confirm access by running firebase projects:list.
Step 3: Build Your Flutter Web App
From your project root, create a release build:
flutter build web --release
The output appears in the build/web directory. This folder contains everything Firebase Hosting needs to serve your app. If you want to experiment with WebAssembly compilation, add the --wasm flag and test thoroughly across browsers.
Step 4: Initialize Firebase Hosting
Run firebase init hosting in your project root and answer the prompts:
- Select the Firebase project you created.
- Set the public directory to
build/web. - Choose "Yes" to configure the app as a single-page app, which rewrites all URLs to index.html.
- Optionally set up automatic builds and deploys with GitHub.
- Do not overwrite build/web/index.html if prompted.
This creates a firebase.json file and a .firebaserc file. The firebase.json file defines the public directory and rewrite rules.
Step 5: Deploy
Deploy your app with:
firebase deploy --only hosting
The CLI uploads your files and returns hosting URLs on Firebase's default domains. Open the URL to confirm your app loads and that navigation and page refreshes work correctly. Every deployment is versioned, and you can roll back to a previous release from the Hosting dashboard.
Step 6: Use Preview Channels for Testing
Firebase Hosting supports preview channels, which create temporary URLs for testing changes before they go live. Run firebase hosting:channel:deploy feature-name to deploy a preview. Share the link with teammates or clients for feedback, then deploy to the live channel once approved. Preview channels expire automatically after a configurable period.
Step 7: Connect a Custom Domain
In the Firebase console, open Hosting and select "Add custom domain." Enter your domain and follow the verification steps, which involve adding DNS records at your domain registrar. Firebase automatically provisions and renews an SSL certificate. Once DNS propagates, your Flutter app will be available securely on your own domain.
Step 8: Configure Caching Headers
Add a headers section to firebase.json to control caching. A recommended approach is to set long cache durations for static assets such as images and fonts, while setting no-cache for index.html, flutter_bootstrap.js, and the service worker file. This helps users receive updates promptly after each deployment while still benefiting from cached assets.
Step 9: Automate Deployments With GitHub Actions
During initialization, Firebase can create GitHub Actions workflows that deploy automatically. Customize the workflow to install Flutter, run tests, build the web app, and deploy to Firebase Hosting. Configure pull requests to deploy to preview channels and merges to the main branch to deploy to the live site. Store service account credentials as encrypted repository secrets.
Step 10: Secure Your Firebase Backend
If your Flutter app uses Firestore, Realtime Database, or Cloud Storage, write strict security rules that only allow authorized users to read and write their own data. Enable Firebase App Check to reduce abuse from unauthorized clients. Restrict API keys to your app's domains in the Google Cloud console, and monitor usage for unexpected spikes.
Performance and Cost Tips
- Use deferred loading to reduce initial bundle size.
- Optimize images and fonts in your assets.
- Monitor bandwidth and storage usage in the Firebase console.
- Delete old releases and expired preview channels if you approach storage limits.
- Upgrade to a paid plan when traffic grows beyond free tier limits.
Troubleshooting
- Blank page after deployment: Confirm the public directory is build/web and that you rebuilt before deploying.
- 404 errors on refresh: Make sure the single-page app rewrite to /index.html exists in firebase.json.
- Old version showing: Review caching headers and perform a hard refresh.
Final Thoughts
Firebase Hosting is one of the easiest and most reliable ways to host a Flutter web app. Build your app in release mode, initialize hosting with the build/web directory and single-page rewrites, deploy with a single command, and use preview channels for safe testing. Add a custom domain, tune caching, automate deployments, and secure your backend rules. The result is a fast, globally distributed Flutter web app that is simple to maintain and ready to scale.
