Check out a free preview of the full Cross-Platform Mobile Apps with Flutter course

The "Building a PWA" Lesson is part of the full, Cross-Platform Mobile Apps with Flutter course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano demonstrates how to build a Progressive Web Application (PWA). The PWA version will run as a website in any browser. However for browsers that support PWAs, the application can be installed and run as a standalone application on the operating system.


Transcript from the "Building a PWA" Lesson

>> So what about the web and PWAs, as I mentioned before? So I already build the web version with flutter build web, and now there is an output folder, so it's build > web, okay? And here you have actually the files that you need to deploy on your web server, okay?

So actually, if I get in build/web and I start the server, for example, I can use npx serve, it's actually a free open source server available on npm. Now I have localhost:3000 that I can open. And this is how the app looks like on Safari. Yeah, we might need to center things, but the app should be working.

Okay, this is Safari. We have a problem, for example, in the favicon at the top, look at that. Yeah, it's the Flutter icon. So I will show you how to replace that. But what happens if I open this in Chrome? So if I open this in Chrome, Chrome supports progressive web apps.

So I have that little icon there, that one. And also, if I go to the menu, it says, Install coffee_masters. If I do that, I will install a progressive web app. It has the Flutter icon. So if I installed the progressive web app, this is how my PWA mapper, this is how it looks like today on my Mac.

I have actually now a Mac application with the name coffee_masters. It also appears as an installed application. And this will work on Windows, Linux, Chromebooks, and Mac OS devices. It also works on iPhones. It also works on Android. So this is the PWA version. It's a web version that can be installed.

And after its installed, it has an icon in the homescreen or in the, wherever place you put apps in that operating system, and it works offline as well. Everything is done with service workers, JavaScript, and PWA stuff. Flutter is creating the PWA for you automatically. The only thing that you need to set or change maybe is the name of the app, the icon, and where is that?

That is actually in the web folder, not the build folder. In the web folder you have index.html to change. You can change anything in the index.html, such as the favicon. So you need to replace the icon. And also have manifest.json. Manifest.json, it's where you set the metadata for your progressive web app, okay?

So for example, here we have the name of the app. So instead of coffee_master, I can use Coffee Masters, the best app, whatever, for coffee. The short_name is actually something that will appear below the icon, so it should be short. The background_color is the background color of your splash screen.

And the theme_color, it's actually used for the title bar. Okay, so it's that color that you see in the title bar. So you can change this, you can change the description as well. Okay, blah blah blah blah blah, we have description, and your icons. Here there is a set of icons, that by default, they have the Flutter icon.

So what do I need to do? Well, replace this icon. So, from the same assets, where you have all the icons, I can take, the only mandatory one is 512 or 1024. So I can put that one there, 1024, that icon. I can delete the Flutter ones. I don't need them.

And now in the manifesto.json, I will just stay with one icon. By the way, who is writing that? That's copilot. Yeah, let me disable the copilot for a while. So 1024 by 1024, and this is icons/1024.png. So if I do this, I think I'm good, yep, now it's better.

So now my app is installed, so I need to uninstall it so I can install it again with a new name and a new icon. So in the menu you can uninstall the PWA in desktop. So we can try again, so localhost:3000. We can install the app. Let me first try to refresh, I'm still getting the, probably, the cached version.

Let me go to inspect application. Yeah, it's still getting the preview's manifest. By the way, if you wanna learn more about manifest and progressive web apps, there are a lot of content in the Frontend Master library, including a workshop that I did on PWAs. And also if you wanna read stuff, I encourage you to read this, kind of book, okay, Learn PWA.

I'm suggesting this one because basically I wrote it. So it's a book that I wrote it with the Chrome team about PWAs. And if you wanna learn everything that you can put in that JSON file, if you wanna read about that, you have this free book, it's free.

Or you can check the videos on progressive web apps. So let's refresh that manifest.json. Let's see if the server is still here. I don't need to restart the server. Well, that server is using some cache, so probably I need to first go, and the typical problem of caching on the web.

So I'm gonna clear the cache, refresh. Let's see if we can get the new manifest. Yeah, my fault. I need to rebuild because I'm still with the old version of the output, okay, yeah. That is the end of the workshop. Okay, so I've done it, so now again, by the way, is this the right one?

No, this is the one, flutter build web. Okay, so now I will get into build web and I will run, The server again. Okay, refresh, now we are getting the new binaries. So when you're trying to install the app, it has the right name, the right icon. And now I have in my Mac, okay, nice app with the name coffee_master.

This is not a native Mac application. It's a progressive web app.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now