CodeNewbie Community 🌱

Cover image for How I Deployed My Flutter Web App to Heroku and Lived to Tell the Tale
Kevin MARVILLE
Kevin MARVILLE

Posted on

How I Deployed My Flutter Web App to Heroku and Lived to Tell the Tale

🎉 The Git Repository

Please click here!

Alternatively, try:

Our

Live Web Application

To view, please click here.

Once upon a time in the land of code and coffee, there lived a brave developer named "X-Cross Dev". With a heart full of ambition and a brain wired for logic, they embarked on a journey to deploy their Flutter web app to Heroku. The mission seemed straightforward, but little did they know, the path was filled with quirky bugs, mysterious errors, and moments of sheer bewilderment.

🚀 The Mission

Deploy a Flutter web app to Heroku and set up a CI/CD pipeline with GitHub integration. Sounds simple, right? Well, buckle up, because this ride has more twists and turns than a season finale of a telenovela.

🧰 The Toolbox

Let's gather our tools:

  • Heroku CLI: Our trusty sidekick for this adventure.
  • GitHub: The fortress where our code resides.
  • Flutter: The magical framework that makes our app come alive.
  • A Big Cup of Coffee: Because no great story ever started with someone eating a salad.

🏗️ Step 1: Setting the Stage

First things first, we need to install the Heroku CLI. If you haven't already, grab it from Heroku CLI. Then, log in using:

heroku login
Enter fullscreen mode Exit fullscreen mode

With a swift command, the door to Heroku's realm opens, and we're ready to create our app:

heroku create my-awesome-flutter-app
Enter fullscreen mode Exit fullscreen mode

📝 Step 2: The Mysterious Procfile

Every hero needs a plan, and ours comes in the form of a Procfile. This little file tells Heroku how to run our app. Create a Procfile in your project root with:

web: npx http-server build/web -p $PORT
Enter fullscreen mode Exit fullscreen mode

📦 Step 3: The Package.json Enigma

Next up, we need a package.json file. This isn't just any JSON file; it's the key to unlocking our app's potential on Heroku. Create one with:

{
  "name": "my-awesome-flutter-app",
  "version": "1.0.0",
  "description": "A Flutter web app",
  "main": "index.js",
  "scripts": {
    "start": "npx http-server build/web -p $PORT"
  },
  "dependencies": {
    "http-server": "^0.12.3"
  },
  "engines": {
    "node": "14.x"
  }
}
Enter fullscreen mode Exit fullscreen mode

🛠️ Step 4: Building the Fortress

Time to build our app:

flutter build web
Enter fullscreen mode Exit fullscreen mode

This command spins the magic, transforming our code into a web-ready format. Now, we need to initialize a Git repository (if we haven't already) and commit our changes:

git init
git add .
git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

🚀 Step 5: The Great Deployment

With our app ready and our code committed, it's time to deploy:

heroku git:remote -a my-awesome-flutter-app
git push heroku main
Enter fullscreen mode Exit fullscreen mode

As the terminal spews out lines of logs, we hold our breath, waiting for the magical words: "Deployed to Heroku."

🔄 Step 6: CI/CD - The Circle of Code Life

To ensure our app stays up-to-date with every code change, we set up CI/CD with GitHub. Head over to the Heroku Dashboard, connect your GitHub repository, and enable automatic deploys for the desired branch.

But wait, there's more! To harness the full power of CI, we need an app.json:

{
  "name": "my-awesome-flutter-app",
  "description": "A Flutter web app",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "env": {
    "FLUTTER_WEB": {
      "value": "true"
    }
  },
  "buildpacks": [
    {
      "url": "heroku/nodejs"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Commit and push, go forth and deploy these changes to GitHub!

🎉 The Victory

With the app deployed and CI/CD set up, we stand victorious. Our Flutter web app is live on Heroku, and every push to GitHub triggers a new deployment. And remember, every bug is just a plot twist waiting to be resolved.

Top comments (5)

Collapse
 
saenhuhuffa profile image
saenhuhuffa

Listening to your introduction is like walking into a fairy tale. The development and acumen of the leader is really important. Reaching out and bringing information to the market and to the users. Success when implementing the right development strategy geometry dash lite

Collapse
 
tomdanny profile image
Tom Danny

Deploying a Flutter web app to Heroku involves setting up your Heroku environment, configuring buildpacks, and pushing your code. Ensure your app runs smoothly by monitoring logs and managing dependencies effectively. Document your journey and share insights with peers. While you celebrate your deployment success, use custom coasters that feature your app’s branding or memorable milestones, adding a personal touch to your workspace and commemorating your achievements.

Collapse
 
filipinus profile image
Fillip • Edited

Deploying your Flutter app to Heroku can feel like an epic journey, and you’ve nailed it! 💥 Bravo on tackling all the twists and turns with perseverance. From Heroku CLI to setting up CI/CD, you’ve built something impressive. Now, as you're honing your skills in tech, don't forget to explore some fun on the side. For example, for betting enthusiasts, here's a guide to downloading Melbet APK for Android and iOS in Côte d'Ivoire. Check it out download Melbet app in Kenya and enjoy the experience!

Collapse
 
nesteroiddd profile image
nesteroiddd

Hello friends! bangladesh is the best bookmaker I have ever used. I like the personalised approach and the many bonuses and promotions that are available for new and regular players. It is especially nice to get up to 10% cashback on casino losses. The app is also very user-friendly and I can place bets right from my smartphone. I am very happy with my choice! I recommend it!

Collapse
 
williamjohn77 profile image
William-John77

Heroku requires a credit card for sign up but I don't have any credit card. Can you suggest me any alternative