The case for Flutter

tldr;

Here's a few hours work -- mostly spent on Flutter's documentation. This' good.

output2.gif

Cross Platform Frameworks

I once, back in 2015, worked with a cross platform framework, Ionic. This was an app rewrite to native Android. That's it. I avoid any work having to do with React Native, Flutter, Xamarin you name them. See. I have been a native iOS, Android dev for more than 5 years now and all has been well for me in this arena. Cross platform tech in my (previous) view is slow, cumbersome to work with, little to no support by major IDEs I prefer, you name it. But that's until Flutter came along.

Flutter hints

I came across Flutter sometime in 2018. My reaction was, "Yet another cross-platform framework 😏". At that time I was in my second year adopting Kotlin at my workplace and was not about to start looking into Flutter.

Just last week, I was thinking of a hobby app. I use such to hone my development skills but I always do them in 2s: iOS (Swift, Xcode and all), then Android (Kotlin, Studio and all). This takes quite some time, as you can imagine, but in the end it's always worthwhile. This time it was different. I wanted an app done -- and fast. Enter Flutter.

One codebase for multiple target platforms is something we've always wanted on mobile -- think what Java did for desktop. And Flutter seems to have nailed it. Or put differently, caught my attention.

flutter_logo.png

The framework

It's been a couple of days playing around with the framework and here are my thoughts.

  • Dart. What a language! Derives a lot from other modern languages. Feels 'fluid' like Javascript, but it's statically typed. It's functional, object oriented, imperative with support for both AOT (Ahead of Time) and JIT (Just in Time) compilation. I'll mention more in the Dart section later in this article.

  • Minimalist structure

Screen Shot 2020-11-04 at 9.45.33 hwa-iniΜ„.png A Flutter project is configured using a yaml file: pubspec.yaml. Assets e.g. images, fonts, sdk, dependencies, project name, description are all declared here. One wonderful thing about the project structure is that you work on the lib directory for the majority of the time.

CLI commands are concise too.

$ flutter create amazing_app

$ flutter run

There's a common phrase in the Flutter community:

Everything is a widget.

How minimalist can it get than that? Flutter is a UI framework and you'll be working with widgets a lot!

  • Composition over Inheritance. This was a favourite discussion point to ask in screening interviews. Let Flutter teach you. The fundamental idea of composition is to promote reusability and enhance decoupling in your codebase. From the sdk itself to the framework API, Flutter is built with composition in mind. Say you need to display a list item for your app. Compose it from widgets. What will be the body of my new awesome screen? You got it. Any widget courtesy of composition! This doesn't mean there's no inheritance. In fact you will often be extending some existing common widgets: StatefulWidget and StatelessWidgets. But the core design of the framework embraces composition to give you control.

  • IDE support. Through the power of plugins, Flutter development is a breeze in VS Code, Android Studio (and IntelliJ) and even on Emacs! The plugins provide formatting, hot reloading, common Flutter code snippets, debugging tools etc.

Flutter is a welcome addition to my tools. Expressive UI, native performance and fast development are some of the biggest benefits you get from it. Learn more at the official website.

Dart

Dart is brilliant. Having done some Javascript, Swift, Java, Kotlin, Typescript, I can appreciate the effort by the language developers in making a modern language. (I'll also use these languages as my references in this section).

dart_logo.png

Some of the key language highlights I have come across are:

  • Type inference. Every modern language needs to have this feature in my opinion. Compilers are becoming smarter with every release. Dart uses the var, final, const keywords to declare a variable. If the context has enough information, it will infer the correct type. You can always provide an explicit type or use casting to disambiguate.

  • First class functions. Dart supports higher order functions with the Function type to represent functions. Single expression functions have a special syntax similar to Kotlin's.

  • Generics. Of course. πŸ™ˆ

  • Extension methods. Swift and Kotlin come to mind. This is the ability of Dart to add a method on an existing type.

  • Null safety. As of the time of writing, this feature of the Dart's type system is in tech preview. The implementation is familiar to Kotlin or Swift users -- types in your code are non-nullable by default. You explicitly declare the nullability of a type using a ? after the type e.g. int?. More information here.

  • Built-in concurrency. Dart has async-await keywords and then-able Futures that allow us to write asynchronous code.

    Future<num> derivePlanksConstant(energy, frequency) async => /* Ask the universe. */;
    

    Streams, json de/encoding, HttpServer 😱, math library, collections, a whole html library and so much more. More on a tour of Dart's libraries.

Grimacing points 😬

Finally, here's a rant on not-so-good things from both Flutter and Dart.

  • State! State is cumbersome to write and understand on the first run. I've found IDEs helpful with the restructuring to accommodate state.

    Disclaimer: I have found out that understanding under-the-hood working of Flutter clarifies why state is implemented this way -- widgets are just blueprints for what to render and state is stored by element in the element tree and not the widget in the widget tree).

  • Underscore for private scope. Seriously Dart?

  • Native platform UI. Flutter controls every pixel by drawing on a canvas. If you need a native platform there's some work on your side. Some widgets are adaptive eg. Switch but still you have to explicitly ask it to adapt to the platform look. In fact, the nature of the platform widgets comes from the material theming. For iOS look and feel, you need to use Cupertino widgets (Cupertino because of trademark issues I presume).

  • Semicolons. I have to include this. Having written quite some Swift code of late, I'm finding myself forgetting the semicolon a lot. This' not a deal-breaker though. We've had a lot more Java days.

Conclusion

Love them, hate them, cross platform frameworks have done well for themselves. Addition of Flutter to the list by a tech giant only suggests there's a need and freelance opportunities online tell the same story.

The speed at which you can spin up an app for both platforms using Flutter is just mind blowing! Having done native development for both iOS and Android, I can appreciate the niche this framework is addressing.

What can I say?

Welcome Flutter to my toolbelt.

Have a project? Let's connect.

Happy coding! 😎

References

No Comments Yet