JavaLand 2022: "Flutter for Java Developers: Web, Mobile & Desktop Front-Ends from 1 Code Base?"
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
JavaLand 2022 was a three-day on-site conference. It ran from March 15 through March 17, 2022; talks were scheduled for the first two days, and the third day was set aside for training.
JavaLand was Germany’s biggest Java conference and had about 2,100 visitors in 2019. The German Oracle User Group (DOAG), the Association of the German Java User Groups (iJUG), and the German publisher Heise Medien organized this conference.
Talk
The year before, I’d given a talk at JavaLand 2021 about “How Should Java Developers Build Front-Ends for Web, Mobile & Desktop Today?”. This talk was the sequel.
My talk took place on Wednesday, March 16, 2022, at 9:00 local time.
Abstract
More and more users were accessing our Java applications through mobile devices. And on mobile devices, native applications often offered a better user experience than web applications. But developing two different, native applications for iOS and Android was usually too expensive and time-consuming.
Cross-platform frameworks promised a remedy here and enabled mobile, web & desktop front-ends with one codebase. For Java developers, Google’s Flutter was the best option. But could Flutter really keep this promise?
I’d developed native applications for iOS and Android with Flutter and brought them to the app stores. Based on my project experience, I described the advantages of Flutter for Java developers, but also typical problems and their solutions. And with a sample application, I demonstrated how mobile, web, and desktop front-ends could actually work with one codebase and what restrictions that entailed.
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 March 2022): After the talk, viewers could give live feedback via Mentimeter on what I should change next time — you could view the second page with the arrow button at the bottom left. That poll is no longer reachable today.
Slides
The slides were available as a PDF (1.8 MB). They had more content and more text than my talking slides.
Historical note (as of March 2022): Back then, the slides were also available in their original Keynote format (12.1 MB) — with less text, but animated and with speaker notes; that file is no longer available today.
Video
At the time of publication, a video was announced to appear behind a paywall.
Get Started With Flutter
My guide had a full write-up on getting started 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. Here were two measurements from my March 2022 report.
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 February 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 February 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:
- The page heading was centered on iOS and left-aligned on Android.
- The “Edit” button was in the navigation bar on iOS and a floating action button on Android.
- 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:
- The “Cancel” button had a text label on iOS and a symbol on Android.
- Fields had no label on iOS, just a placeholder when they were empty. Android had both a permanently visible label and a placeholder.
- Text fields on iOS had a “Clear” button. Android didn’t have such a button.
Native Cross-Platform Frameworks
More 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 were two more approaches I researched for this talk:
- Kotlin Multiplatform Mobile: If I understood it correctly, it added a Kotlin back-end to native iOS & Android applications. To me, that made things more complicated, not simpler. And yes, I also knew about (Kotlin) Compose Multiplatform — JetBrains’ port of Jetpack Compose, Google’s new Android UI framework inspired by Flutter — but it didn’t run on iOS yet at the time, so it was disqualified.
- Codename One: a Java framework “for building high quality, cross-platform native apps for Android, iOS, Desktop & Web”. And no, I hadn’t heard of that either before this talk. 😁 They claimed 40k+ developers. That went to show that the pain of separate iOS & Android apps was large enough to attract many players.
Popularity. I said that Flutter was most popular with developers but only second place with employers. This was based on the same monthly Java report measurements. Here were two measurements from my March 2022 report.
Employers: Job Ads. The Indeed job search was active in 63 countries representing 92% of the worldwide GDP in 2020. Flutter was the baseline. Measurements were from August 2021 through February 2022.
React Native won, Flutter was second, Xamarin third, and JavaFX last. Flutter had closed nearly a third of the gap to React Native, which had nearly twice as many mentions as Flutter. Both Xamarin and JavaFX declined both absolutely and relatively — JavaFX dramatically so.
Developers: Students at Udemy. This time, React Native was the baseline. Measurements were from March 2021 through February 2022.
Flutter won, React Native was second, Xamarin third, and JavaFX fourth. Flutter had increased its lead over React Native, while Xamarin had lost ground against React Native. JavaFX grew, but from a lower base level.
Links to the courses: Flutter, JavaFX, React Native, Xamarin.
The Flutter 2.10 announcement at the time said that “nearly half a million apps use Flutter”.
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
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
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.
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.
Firebase 👍🏻
I also had a guide dedicated to getting started 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.
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).
Back To Basics
My guide to getting started with Flutter had an architecture section that explained my proposed use of components & layers.