Skip to content

London Java Community: "Flutter for Java Developers: Mobile, Web & Desktop with 1 Codebase?"

Published on · Updated on · 10 min read
Talk title card

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 could essentially do everything native SDK apps did, but with a faster build & deploy experience. And we Java developers liked Flutter because its language, Dart, was a “simplified Java, tuned for UI development”.
  • Compared to frameworks like React/Angular/Vue, Flutter web only had the material design look & feel vs. hundreds or 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 instead for most cases. If you still wanted a desktop application: Flutter was only stable on Windows (since February 2022) at the time, not on Mac and Linux. 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 an open question whether they’d always be maintained going forward.

I couldn’t generally recommend the two Java front-end libraries, Jakarta Server Faces (JSF) and JavaFX:

  • JSF couldn’t build the single-page applications (SPAs) we got from frameworks like React, Angular & Vue. It was very unpopular with developers and unpopular with employers and hadn’t received any new features in five years (Jakarta EE 10 was to bring an update in mid-2022).
  • JavaFX used a UI build tool, not the more modern UI-as-code approach. On mobile, it couldn’t produce a native look & feel and didn’t have access to all native features. It was unpopular with both developers and employers.

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

  • Web developers: Use React Native
  • .NET developers: Use .NET MAUI
  • Java developers who absolutely needed to include one or more legacy Java libraries: Use JavaFX
  • Else: Use Flutter

My slides showed why I came to this conclusion.

Logistics

Conference

The London Java Community (LJC) regularly hosted free online talks by industry experts.

Talk

My talk took place on Tuesday, April 26, 2022, at 1:00 pm British Summer Time. It was called “Flutter for Java Developers: Mobile, Web & Desktop with 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 and desktop front-ends, too! And Google said Flutter was “the most popular cross-platform UI toolkit” with half a million apps. I thought Google’s Flutter was the best cross-platform option for Java developers. But could it deliver?

I had put a native Flutter application into the iOS and Android app stores. My talk described how Flutter worked and how it was different from other solutions. Based on my experiences, I discussed the advantages and problems of Flutter. And a sample application demonstrated a native look & feel across mobile, web, and desktop with one codebase.

Who Made Me the Expert?

I’ve been a Java developer for 26+ years and still write code every day. As a Java news reporter for InfoQ, I knew what was going on in the Java world. On the QCon London 2022 & QCon Plus Spring 2022 program committees, I helped organize the Java and front-end tracks, so I knew what was going on in the industry, too.

I was neither affiliated with the projects I discussed nor selling books or training courses. I shared industry analysis and my project experiences to give you options for your next project. But in the end, you had to decide!

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

Slides

The slides were available as a PDF (9.8 MB). They had more content and more text than my talking slides.

Download slides (PDF)

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

Video

The old bundle didn’t list a video for this talk.

Get Started With Flutter

My guide had a full write-up on getting started with Flutter.

Start with Flutter

Additional Talk Information

Cross-Platform Front-Ends

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 63 countries. For developer popularity, I used online training students, Stack Overflow questions, and Google searches.

Employers: Job Ads. The Indeed job search was active in 63 countries representing 92% 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. Measurements were from August 2021 through April 2022.

React won, Angular was second, Vue third. After an Angular surge the previous September, React was pulling away from Angular again. Vue was slowly gaining on Angular and had nearly reached half of Angular’s mentions. JSF was an order of magnitude behind Vue.

Developers: Students at Udemy. Udemy was one of the biggest online learning sites. It published the number of courses and the number of students (beyond a certain threshold). This showed how many developers 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). Measurements were from March 2021 through April 2022.

React won, Angular was second, Vue third. React was steadily increasing its lead over Angular. Vue was stuck at 40% of Angular’s students.

Links to the courses: Angular, React, Vue.

Native Look & Feel?

Native look & feel mattered, 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: In order to “really make products feel great on Apple platforms”, Google was switching to native iOS UI elements.

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

Here was the “My Data” page from my app, on iOS (left) and Android (right):

Three differences stood out:

  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:

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. Android had both a permanently visible label and a placeholder.
  3. Text fields on iOS had a “Clear” button. Android didn’t have such a button.

How Flutter Works

Widgets

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

I had a guide to getting started with declarative development:

Start with Declarative Development

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

Widget Sets

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

Check out the sample application

Code, Build & Deploy

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

Watch the video (YouTube)

My Flutter Experiences

My Project

The start-up I co-founded was called “Your Home in Good Hands”. At the time of the talk, it was in private beta; the service was due to launch publicly later in 2022.

Flutter 👍🏻

I had a page dedicated to getting started with Flutter, which went into more detail.

Start with Flutter

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

But I did build a prototype in 2019 which at least showed a Flutter app in motion. Although it was old by the time of the talk, 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, NoSQL 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 guide dedicated to getting started with Firebase.

Start with Firebase

Mobile Power

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 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

My guide to getting started with Flutter explained the use of Redux as a data store.

Here was another example of UI inconsistencies: 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):

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.

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

Here was the mobile app for cat-sitters:

And here was 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 shade 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).

Some good design books on the topic:

Back To Basics

My guide to getting started with Flutter had an architecture section that explained my proposed use of components & layers.