Inserting the same Flutter web app into different sections of your website

When I thought about the content for Design Your City, I faced a dilemma.

I had an idea for 4 tabs.

– “Learn” tab: content, should be picked up by search engines.
– “Discover” and “Design”: CAD tools
– “Account”: log in/out for the CAD tools

My requirements were like this:

A design mock up showing 4 tabs: Learn needs web content with SEO, discover, and design and account, need web app content (maps and login/out)

(Note: the website has slightly expanded now, with 6 tabs)

I knew from the official doc, and from my own experimentation with Flutter For Web on a previous project, that Flutter For Web is very well suited to make CAD tools, but not for SEO.


I really cared about the learning section of the website, but it made no sense to have it if it wasn’t going to have good SEO.

So I had no choice but to roll up my sleeves and do a couple of POCs to find out how it could all hang together.


My setup


After trial and error, I ended up with the following:

– I use plain JS for the tabs for the website.

– Everything is hosted on Firebase: the website is hosted on the main domain (I linked my domain to Firebase) and the web app is hosted on a Firebase subdomain.

– I have one Flutter project, which is an app with 3 tabs (“Discover”, “Design”, “Account”). When I develop the app, I have 3 tabs in the project, so I can navigate. BUT those tabs aren’t shown when I load it from the website.

– I use a single iFrame in my website index.html file. I use an event to tell the Flutter app which tab the website wants. This is that same event that also allows me to hide the tabs in the Flutter web app. So it’s the same instance of the web app running in the 3 tabs.


The website code


I found a great JS tutorial to set up tabs on a website. I use almost the same set up as in that tutorial.

The only difference from the tutorial is I have a div for each web tab (3 of them now on Design Your City: “Be Inspired”, “Learn”, and “About Us”), and a separate div for the Flutter web app. A separate div enables each web content tab to retain its content.

The 3 tabs that show the web app (“Discover”, “Design”, and “Account”) display the same div. The div has a simple iFrame, pointing to my Firebase subdomain where the Flutter app is deployed. The Flutter app retains the content for each tab, using a PageController.

To communicate with the Flutter web app, I use an event. This is run in a method openTab, which I trigger in the a tag, like this:

The code in openTab:

content is the id of my iFrame.

Now, that’s the web side sorted. Let’s move on to the Flutter web app part.


The Flutter web app code


My main widget is PagesScreen. In it, I use a PageController.

Let’s define the pages (basically, a list of widgets):


It’s a StatefulWidget, and in the initState method, I listen for the web event (and I dispose of the listener in dispose).

By default, tabs are shown in web app. But, when I receive a web event, tabs are disabled.

Note: In the code below, you will notice getInstance –> this is simply my injection code. For this app, I use my own injection setup, but you could use whatever you want here, this blog post isn’t about arch or state.


WebEventListener is an abstract class as below:


My implementation class is as below:



With that setup, I have tabs when I run the app on its own, but not when it is in the iFrame, as the website has tabs already.

Finally, I use a PageView to show the correct page. It uses a Bloc (PagesBloc) to show the correct page. This blog post isn’t about arch or state management, you can use whatever you like for that.


All working….

Until I tried to run a test!

(Yes, I love tests – Unleash The Full Power of Flutter Widget Tests)


Tests don’t like dart:html


I got an error message new to me:



So, what to do?

Well, thankfully, I don’t need dart:html for the functionality itself, it is only used for listening to events from the website.

At first, I tried creating a second implementation class for WebEventListener but I got the same error. Even though I wasn’t using the class above (I was injecting a different class, which basically was doing nothing), it still tried to build that class I wasn’t using.

So, I’ve got a hack I don’t like, which is I comment code out. That means I need to change code when I deploy to Firebase, but I use the code below for development.



Do I like this? Hell no! But I absolutely want tests and dart:html functionality isn’t required for the web app to work, so I live with this hack.

Note: if someone knows of a better way, please let me know! I tried to run tests with flutter test --platform chrome but I got many errors, different ones, and so I decided to not bother.



As I’m working on Design Your City, I will write more blog posts about Flutter for Web. But, in a nutshell, I can say: “Thank you to Flutter team for enabling me to make web apps.”


Author: Natalie Masse Hooper

Mobile app developer with 14 years experience. Started with the Android SDK in 2010 and switched to Flutter in 2017. Past apps range from start ups to large tech (Google) and non tech (British Airways) companies, in various sectors (transport, commercial operations, e-commerce).