Skip to content

Angular Community Meetup Talk: "Flutter For Angular Developers: Mobile, Web & Desktop from 1 CodeBase"

Published on · Updated on · 17 min read
Angular Community Meetup 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 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 vs. thousands of design systems, component libraries, and UI skins. And because Flutter couldn’t use JavaScript libraries, it just had a tiny number of libraries vs. hundreds of thousands of JavaScript libraries for React/Angular/Vue.
  • On the desktop, I thought a web application was fine for most cases. If you still wanted a desktop application: Flutter was barely stable on Windows (since February 2022) and on Mac and Linux (since May 2022). On the plus side, Flutter could call into desktop libraries with C++. But the third-party widget sets for Windows & macOS look & feel were incomplete. And it was unclear whether they’d always stay maintained going forward.

For Angular developers, I thought React Native was a better first choice than Flutter: language, UI elements, styling, layout, libraries — it was the same as Angular or very similar. And twice as many job ads mentioned React Native. On the downside, Flutter was up to twice as popular with developers.

Here was my recommendation on which cross-platform framework to use on mobile, based on the knowledge of the developers:

  • Web developers: try React Native first. If that failed, use Flutter.
  • .NET developers: try .NET MAUI first. If that failed, use Flutter.
  • Everybody else: try Flutter first. If that failed, use React Native.

See my slides for why I came to this conclusion.

Logistics

User Group

The goal of the Angular Community Meetup was to help developers from across the globe, regardless of skill level, learn and level up their Angular skills. They organized one monthly meeting for Europe & Africa and one for the Americas.

Talk

My talk “Flutter For Angular Developers: Mobile, Web & Desktop from 1 CodeBase” was part of the Europe & Africa meeting on Tuesday, June 14, 2022, from 18:00-20:00 BST.

Abstract

Angular applications worked on PC and phones. But they faced restrictions on mobile (no push notifications on iOS, limited local storage, etc.). And native applications could use all platform features and had the native look & feel. So how could we add native mobile apps to our Angular app?

Building two different applications for iOS and Android was too expensive. Cross-platform frameworks promised salvation and delivered iOS and Android apps with one codebase. Google’s Flutter even gave us web & desktop front-ends, too! So, did Flutter deliver? And when should we Angular developers use it?

Who Made Me the Expert?

I’ve been a Java developer for 26+ years and still write code every day. I’d been an Angular developer for four years and a Flutter developer for two years. I was a Java news reporter for InfoQ, so I knew what was going on in the Java world. In the QCon London 2022 & QCon Plus Spring 2022 program committees, I helped organize the Java and front-end tracks — that kept me close to industry trends, too.

I wasn’t affiliated with the projects I was discussing, and I didn’t sell books or training courses. I shared industry analysis and my project experiences so you could build better projects faster.

Historical note (as of June 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 talk is on YouTube:

Watch the video (YouTube)

There’s also an extended version where I answered some questions from the moderator first.

Watch the video (YouTube)

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

Download slides (PDF)

Historical note (as of June 2022): Back then, the slides were also available in their original Keynote format (8.4 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

Here are links & information for getting started with mobile apps using React Native.

Get started with React Native

And here are links & information for getting started with Flutter.

Get started with Flutter

Additional Talk Information

Why Flutter?

Native Look & Feel?

The slides mentioned native look & feel and that it’s 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 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.

Native Cross-Platform Frameworks

Building two separate native apps for iOS and Android was very expensive. That’s why there were a ton of frameworks & tools to build one app and get two native mobile apps. My talk mentioned Flutter, React Native, Xamarin/.NET MAUI, and JavaFX. Here are a couple more:

  • Qt: this framework went back to the 90s. Nokia owned it at one point. It stood out because you could build front-ends for embedded devices, too.
  • Codename One: this Java-based framework for mobile, web & desktop seemed to be a direct JavaFX competitor. I’d never heard of it before researching my talk. They claimed to be “Trusted by 40k+ developers”.
  • Volt MX: this was a low-code framework for building both the front-end and back-end of an application. It had a visual designer and component libraries. JAX had a German talk about it.

How Flutter Worked

I had a page dedicated to getting started with Flutter.

Get started with Flutter

Would Google Kill Flutter?

Here was the “Killed by Google” website, a list of discontinued Google products.

The Angular website from May 11, 2022 said “For web, mobile web, native mobile and native desktop.” The Flutter website had a showcase for Toyota using Flutter in their Linux infotainment systems. And a Canonical blog post discussed their use of Flutter in Ubuntu. The Flutter-based installer wasn’t available as of May 11, 2022.

Programming Language: Dart

Here is a language tour of Dart by Dart itself. And here is a Google Code Lab called “Intro to Dart for Java Developers”.

Widgets

Widgets were code. Flutter used the so-called declarative programming model. The old way of doing things is called imperative programming, by the way.

I had a guide to getting started with declarative development:

Get started with declarative development

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

Code, Build & Deploy

The quote “create an SDK that developers love” was from the Flutter roadmap as of March 17, 2022.

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

Watch the video (YouTube)

My Flutter Experiences

My Project

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

Flutter 👍🏻

Yes, Flutter on mobile worked. Flutter had some minor issues at times. For instance, the Flutter app sometimes didn’t terminate, and you needed to kill it manually.

When there was trouble, it usually came from Apple. For instance, at some point I could no longer copy text from the clipboard into a Flutter app in the iOS simulator — so I nearly knew my long password by heart! 😁 That had started a couple of months earlier, and I didn’t know when it would be fixed.

I wished there had been more help from Flutter for showing the native look & feel. The Flutter team always said you should “customize Material UI”, not use native look & feel. But I built my own widgets anyway to centralize configuration, so I managed.

The Flutter team did listen, though. For instance, when the Flutter community worried about too many bugs piling up a couple of years earlier, the Flutter team hired external developers to fix bugs. They also ran quarterly user surveys and made changes based on the feedback.

I wasn’t ready to fully share our app yet. We had screenshots on our home page, but they were already 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)

Native 👍🏻

The “Native Look & Feel?” section above already showed how my app implemented a native look & feel and how that differed between iOS & Android.

The screenshot showed my custom list tile on iOS, since Flutter’s iOS widget set didn’t have one. I built it as a custom widget based on a plugin.

There were three noteworthy things:

  1. This was a so-called sliver app bar that was initially taller than usual. When you scrolled down the page, the app bar shrank to its normal size, and the “Loaded: 3m ago” text disappeared.
  2. This was a sliding segment control. Apple added it to iOS 13 in September 2019. It took a couple of months until Flutter added it to its widget set.
  3. These buttons were custom widgets of mine. They looked the same on Android.

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 complicate our apps 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.

Flutter vs. React Native

Popularity

App Stores

The source for the app analysis chart was this report by Appfigures. My numbers combined the Apple App Store and the Google Play Store:

Framework Apple App Store Google Play Store Average Share
React Native 11% 13% 12%
Flutter 7% 13% 10%
Xamarin 4% 4% 4%

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. Flutter was the baseline.

React Native won, Flutter was second, Xamarin third, and JavaFX last. React Native and Flutter were back to their March levels. React Native led Flutter 2:1 again. Xamarin had lost slightly while JavaFX had gained 10%. The initially high JavaFX numbers had been a counting error of mine: they came from Japan and disappeared in October the previous year.

Developers: Students at Udemy

Udemy was one of the biggest online learning sites. They published the number of courses and students beyond a certain threshold (possibly around 100,000 students). This showed how many people evaluated a technology. This time, React Native was the baseline.

Flutter won, React Native was second, Xamarin third, and JavaFX fourth. Slowly but surely, Flutter had been increasing its lead over React Native — in less than a year, it would lead React Native 2:1. Xamarin had actually declined in the number of students — I didn’t know why either! JavaFX had been steady for the last seven months.

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

Developers: Google Searches

Google Trends demonstrated the initial interest in a technology over time. “More searches = better” to me.

This link produces the chart above.

Flutter won, React Native was second, Xamarin third, and JavaFX fourth. Flutter had twice the search volume of React Native. Flutter also grew faster than React Native and had just hit an all-time high, while React Native was only at two-thirds of its July 2019 peak. JavaFX and Xamarin had declined for five years, though JavaFX had trended slightly up in the last year.

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.

Flutter won, React Native was second. Flutter had nearly twice the questions React Native had and showed much more robust growth. Both frameworks were about 8% off their recent all-time highs. JavaFX and Xamarin had declined for 4-5 years.

Developers: Developer Survey

The chart from the popularity survey among mobile developers was from Statista. The JetBrains “State of Developer Ecosystem” reports from 2019-2021 were the source for this chart.