07-01-2022
From Native to Flutter, a developer story
by Lucas Sousa, Mobile Developer @ Xpand IT
Before getting to know Flutter, I was a Native iOS developer, which got me really excited with the SwiftUI’s announcement. I had always considered UIKit work much more hassle than it was necessary to draw pixels on the screen, therefore I was excited about a new, simpler declarative way. It was fantastic that the same app, which would take several lines of code to do on UIKit could be done in just a few dozens of SwiftUI. I was immediately sold.
Develop UIs in real time
Then, there was hot reloading too [immediate update of the developing file when there are code changes]. I mean, it works a little different than React Native and Flutter’s hot reloading, but finally, there was a workflow for quickly developing iOS UI by code and seeing the result in real time. Swift code takes a long time to compile, especially large codebases such as most enterprise apps. So, this is really a developer life improvement.
Then comes Flutter
Later in life, I got an opportunity as a Flutter developer. Dart is a very consistent language and has great tools and environment. Learning was easy and I knew that Flutter’s declarative approach to the UI was very similar to what I had with SwiftUI. On Flutter, everything is a Widget and they are redrawn every time the state changes, just like SwiftUI.
Let’s compare
Compared to SwiftUI, Flutter is a lot more verbose: The same UI will take more characters to look the same. However, there are big advantages:
- State Model is more consistent. Dart didn’t have to be modified to handle the state on Flutter. Swift had to add reserved words [a word in a programming language that has a fixed meaning and cannot be redefined by the programmer] to the language. Dart is more concise and has a more consistent language than Swift;
- Widget behaviour is more consistent. SwiftUI has *hidden defaults* and that is considered harmful.The same code would produce vastly different UIs on different versions of SwiftUI’s framework.
- Multiplatform is an obvious one. SwiftUI is multi-platform and works well on all Apple stuff (iOS, Mac, WatchOS). Flutter, however, works well on both mobile platforms such as Android and iOS. And also works very well on the desktop (Windows, Mac and Linux), and even can produce PWAs (Progressive Web Apps) for the web.
- Another one is support. SwiftUI has a huge drawback that it only runs on iOS 13 forward. And this was the first release of SwiftUI. Newer ones only work on iOS 14 and 15. I was impressed that when I’ve first tried flutter, it would run even on iPhone 5c (iOS 10). Flutter, had better old iOS device support than Apple by a really large margin.
I will not hide the drawbacks, though.
- Binary/File Size: a drawback from Flutter, very apparent on iOS platform is the binary size. A flutter app typically would build a 20 MB APK (android) and a 50–70 MB on iOS. (Newer versions of Flutter have promised better compression for iOS on future releases, though). With SwiftUI you can have a small app be less than 10 MB, even less than 3 MB download size when you take download size seriously.
Verdict
I consider that visual consistency, consistent behaviour and platform support are more valuable than the smallest binary. In fact, most Enterprise apps, usually have lots of assets and code, and thus have larger sizes. Therefore, the minimum sizes achievable in Flutter are not a problem for them (especially when a lot of famous apps have over 300 MB download size). Flutter is a better option for Business.
TLDR about Flutter vs SwiftUI
Similarities:
Both Flutter and SwiftUI are declarative UI frameworks that react to the change of state.
UI is redrawn when observed variables change
PROS of Flutter:
- More consistent Language. Easier learning curve from a beginner.
- Visual Behavior is predictable;
- Multiplatform support (Android, iOS, Windows, Mac, Linux and Web)
- Old Devices Support. Supports old iOS devices deprecated by Apple.
CONS of Flutter:
- Larger binary size, especially for iOS
- More verbose code than SwiftUI.
PROS of SwiftUI:
- Smaller codebase, less verbose to achieve good looking UIs;
- Smaller Binary Size;
- Same UI can Run on iOS, MacOS and even WatchOS.
CONS of SwiftUI:
- Only Apple Devices;
- Lack of Old Device Support. iOS 13 or newer;
- Hidden defaults, less predictability;
- UI Visually changes on newer releases. Less consistency.
Conclusion
If you would choose between learning SwiftUI or Flutter, I would advise you to stick with Flutter. There is a lot more opportunity and advantages with that.