Skip to content

QCon Plus 2022: "Google’s Flutter: Mobile, Web & Desktop Frontends from 1 Codebase?"

Published on · Updated on · 12 min read
QCon Plus logo

Share

Summary

Yes, we could build front-ends for mobile, web, and desktop from one codebase with Flutter. I wrote a sample app to demonstrate it. But I only recommended Flutter on mobile:

  • Flutter on mobile gave us “2 apps for the price of 1”. Flutter code could use native libraries because it could call native code (and vice versa). It could also show both native screens and web views. So Flutter essentially could do everything native SDK apps did, but with a faster build & deploy experience.
  • Compared to frameworks like React/Angular/Vue, Flutter web only had the material design look & feel and a small number of libraries.
  • On the desktop, I thought a web application was fine instead for most cases. If you still wanted a desktop application: Flutter was only stable on Windows (since February 2022), not on Mac and Linux.

See my slides for why I came to this conclusion.

Logistics

Event

QCon Plus brought together the world’s most innovative senior software engineers across multiple domains to share their real-world implementation of emerging trends and practices.

Talk

My talk was on Tuesday, May 10, at 12:20 EDT. It was called “Google’s Flutter: Mobile, Web & Desktop Frontends from 1 Codebase?”.

Abstract

The phone was the main computer for consumers at the time. Even enterprise users increasingly relied on mobile devices. Native mobile applications often provided a better user experience than web applications. But developing two different applications for iOS and Android was usually too expensive.

Cross-platform frameworks promised salvation and delivered iOS and Android apps with one codebase. Like Google’s Flutter, some even gave us web & desktop frontends, too! And Google said Flutter was “the most popular cross-platform UI toolkit” with half a million apps. So, did Flutter deliver?

Historical note (as of April 2022): After the talk, attendees could give live feedback via Mentimeter on what I should change next time. That poll is no longer reachable today.

Slides & Video

The recording and transcript of the talk were available on InfoQ:

Watch the video and read the transcript on InfoQ

The slides were available as a PDF (11 MB); the PDF version is available for download here.

Download slides (PDF)

Historical note (as of April 2022): Back then, the slides were also available in their original Keynote format (10.8 MB) — with less text, but animated and with a look behind the curtain of individual effects, including speaker notes; that file is no longer available today.

Get Started With Flutter

Here’s my page for getting started with Flutter.

Get started with Flutter

Additional Talk Information

How Cross-Platform Frontends Worked

Web Framework Popularity

I said that React, Angular & Vue were the three most popular frameworks. I knew because for my monthly Java report, I measured the popularity of JVM languages, databases, back-end frameworks, and front-end frameworks. I measured popularity among employers through job ads from 62 countries. For developer popularity, I used online training students, Stack Overflow questions, and Google searches. Here are two of the four measurements from what was then my upcoming May 2022 report.

Employers: Job Ads

The Indeed job search was active in 62 countries representing 89% of the worldwide GDP in 2020. It demonstrated the willingness of organizations to pay for a technology — the strongest indicator of popularity in my mind. Angular was the baseline. With 0.6% and 0.4%, respectively, Thymeleaf and Vaadin were missing from the chart.

React won, Angular was second, Vue third. React surged 11% the previous month, nearly leading Angular 1.5:1 by then. Angular still lost 6% mentions over the previous two months. Vue held steady at half of Angular’s volume. JSF was an order of magnitude behind Vue and had been steady for the previous six months.

Developers: Google Searches

Google Trends demonstrated the initial interest in a technology over time. Thymeleaf wasn’t on the list because Google only allowed 5 search terms. “More searches = better” to me.

This link produces the chart above. Here’s a version with Thymeleaf instead of Vaadin: Thymeleaf also flat-lined.

React won, Angular was second, Vue third. React was nearly back at its July 2020 peak and had twice the search volume of Angular. Angular only had two-thirds of its July 2019 peak. Vue had peaked simultaneously but had remained flat at half of Angular’s volume for a year. All other frameworks were insignificant against these three.

Developers: Students at Udemy

Udemy was one of the biggest online learning sites. They published the number of courses and the number of students beyond a certain threshold. This showed how many people evaluated a technology. Angular was the baseline. The other frameworks didn’t cross the reporting threshold for Students at Udemy (maybe around 100,000 students).

React won, Angular was second, and Vue was third. React was slowly pulling away from Angular, while Vue caught up even slower.

Here are the links that showed the courses for all and the number of students for some:

Developers: Questions at Stack Overflow

Stack Overflow Trends shows which percentage of questions at Stack Overflow have a particular technology tag. It was a proxy for using a technology during evaluation and productive use. “More questions = better” to me.

This link produces the chart above.

React won, Angular was second, Vue third. React had grown spectacularly for seven years. After briefly exceeding 6% of all questions at Stack Overflow, it was now taking a breather. Angular’s 3.5-year decline seemed to have stopped. Vue had declined for half a year and was now back to early 2020 levels. JSF, Vaadin, and Thymeleaf barely registered against the “Big Three”.

Native Look & Feel?

Native look & feel was important, especially on mobile, where a vocal minority would complain if an iOS app looked like an Android one and vice versa.

Google’s own apps, like Google Maps or Google Mail, had used mostly Material Design UI elements on iOS for years. Not anymore: to “really make products feel great on Apple platforms”, Google switched to native iOS UI elements.

If you didn’t use both iOS and Android regularly, you wouldn’t know that they were meaningfully different. Even if you tried to make them look and feel as similar as possible!

Here were three differences:

  1. The page heading was centered on iOS and left-aligned on Android.
  2. The “Edit” button was in the navigation bar on iOS and a floating action button on Android.
  3. When you could tap on a table row on iOS, it had a chevron on the very right. Android didn’t have such an indicator.

Forms were also different:

Here were some differences:

  1. The “Cancel” button had a text label on iOS and a symbol on Android.
  2. Fields had no label on iOS, just a placeholder when they were empty. They had both a permanently visible label and a placeholder on Android.
  3. Text fields on iOS had a “Clear” button. Android didn’t have such a button.

UI As Code

Flutter used the declarative programming model. I had a guide to getting started with that:

Get started with declarative development

How Flutter Worked

Widgets

Flutter didn’t use native UI elements (such as text fields or buttons). Instead, it emulated them. See here for more details.

Widget Sets

I built a sample Flutter application with five different, native “look & feels” from one codebase: web, iOS, Android, Windows, and Mac. I showed screenshots during the talk. You could run it yourself if you had Flutter installed!

Check out the sample application

My Flutter Experiences

My Project

The start-up I’d co-founded was called “Your Home in Good Hands”. As of April 2022: we were in private beta; our service was set to go public later that year.

Flutter On Mobile 👍🏻

I had a page dedicated to getting started with Flutter.

Get started with Flutter

Flutter Hot Reload made code changes go live on the device/simulator immediately. It was the main reason why working with Flutter could be such fun! Here is a video demonstrating it.

Watch the video (YouTube)

I wasn’t ready to fully share our app yet. We had screenshots on our home page, but they were slightly out of date by then.

But I did build a prototype in 2019, which at least showed a Flutter app in motion. Although it was old by then, it was still a decent example of what a native Flutter app could look like. It took me about six weeks and was my first Flutter project. I used Google’s cloud service Firebase for login, No-SQL database, and file storage. I also built my own back-end with Java, JHipster, Spring Boot, and Angular.

Watch the video (YouTube)

Firebase 👍🏻

I also had a page dedicated to getting started with Firebase.

Get started with Firebase

Mobile Power

Mobile phones were very powerful. They had powerful CPUs and lots of local storage. So when developing for mobile, we should think of phones more like a PC, less like a web browser.

One way to harness that power was to load and save data in the background.

  • My app loaded a lot of data in the background. So when the user hit many screens, there was no wait like there often was on web pages — the data was already there! But then my app immediately refreshed the data to make sure the user saw the latest data. This also helped when the phone was offline: the data was already there.
  • For many operations, my app also saved in the background. So the app stored the data locally and returned control to the user. It then sent the data to my back-end in the background. Again, this helped when the phone was offline: the data remained on the phone until the user was online again. Saving in the background only worked when we didn’t expect errors from the back-end (like form validation errors): we couldn’t show errors easily because the user had already moved on to other screens. And saving in the background could make our apps more complicated because we sometimes had to “manually merge” our locally stored data into the data we loaded from the server.

Now storing data locally and loading & saving data in the background was easy with Flutter. But we could also do that in a web application — more difficult and more restricted, but doable.

I knew because at the end of 2019, I’d built such a web application: a so-called progressive web app (PWA). A PWA used the “Service Worker” in a browser to install on your device and cache data. It took about four weeks, and it was my first PWA. I used Google Workbox for this but developed my own offline storage solution in the browser. I built my back-end with Java, JHipster, Spring Boot, and Angular.

Watch the video (YouTube)

One Source Of UI Truth

This is how I made sure my app UI didn’t get “out of sync”. Let me show you two examples of UIs that were “out of sync”.

This was the iPad app of the UK price comparison site Pricespy. That app wasn’t sure whether my list had seven items (top left) or just three (right).

And here was the macOS App Store. I’d just added $75 to my account, which was now $113.38 (see the top right). But at the bottom left, it still said $38.38!

So I’d just given money to the most valuable company in the world. And it couldn’t figure out how much was in my account… That was embarrassing if you asked me! It took a couple of hours until the App Store was back in sync.

So how to fix this? There were many different ways. I went with a global data store. My Get Started with Flutter guide explains the use of Redux as a data store.

But that wasn’t enough. We also had to remove duplicates from our locally stored data. Here’s an example from my app:

The task home page (left) showed a chart with statistics about how many visits were already completed. The visit list (right side) showed a list of those visits. Initially, I stored this as two different data structures in my app: visit statistics and a list of visits. Now they could get out of sync, too: a user just finished a visit, which triggered a refresh of the visit list. But the app didn’t refresh the visit statistics, so the task home page would show an incorrect, out-of-date chart.

So my solution was to get rid of storing the visit statistics altogether. Instead, the app calculated visit statistics for the chart on the left in real time, iterating over all the visits and checking their status. And yes, my app could do that because phones were powerful — see the previous section.

Be Consistent

My start-up offered a web app for managers and a mobile app for cat-sitters. So arguably, consistency between them was nice-to-have.

Now most managers were also cat-sitters. So they used both apps. This made consistency a necessity!

So let’s look at the two apps. Here is the mobile app for cat-sitters:

And here is the web app for managers:

So how was this consistent — or how was it different?

  • Both apps used different navigation paradigms. The mobile app had a nav bar at the top (1) and a tab bar at the bottom (2). The web app had breadcrumbs (1) and a header (2).
  • Both apps shared the same colors. For instance, the mobile nav bar (1) & tab bar (2) and the web app breadcrumbs (1) all used the primary brand color. Navigation also used the same kind of blue (3).
  • The apps also used the same Google font for headings (4): Montserrat.
  • Finally, the apps shared symbols from Font Awesome: a walking person in this example (5).

Here are some good design books:

Back To Basics

Writing mobile apps was still writing software. So the same best practices applied here, too:

  • The best code is the one you don’t have to write. So reuse code somebody else wrote! In Flutter, this meant using a plugin.
  • DRY: don’t repeat yourself. So instead of applying the same configuration code to widgets over and over, we should create our own widgets.
  • We should also structure our applications with best practices. That meant horizontal layers and could mean vertical layers.

My Get Started with Flutter guide has an architecture section that explains my proposed use of components & layers.