If you guys are like me and you always want to keep step with latest and best technology available out there then you are already thinking about migrating to Flutter for your new mobile applications. Some of you already tested Flutter, some of you only heard about it and some of you already think about migrating your applications from Java and Kotlin to Dart powered Flutter.
Flutter is Google’s mobile app SDK for crafting high-quality native interfaces on iOS and Android in record time. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
I’m not going to talk about all advantages of using Flutter for your mobile development. For me the most important is Unified app development. With Flutter you get tools and libraries to develop applications for Android and iOS. If you already have application you can continue to use all your existing Java, Kotlin, ObjC or Swift code and use Flutter only for your Views. This saves you so much time.
If you are Android developer you should know this about Flutter:
Forget about Java or Kotlin Flutter is using Dart. Dart is language developed by Google. It is used to create high-quality, mission-critical apps for iOS, Android, and the web. Dart apps run natively on iOS, Android and beyond. With Flutter you can easily develop for iOS and Android without need to learn Swift or Kotlin. Only language you need to know is Dart.
No more Views, meet Widgets. Flutters widgets are lightweight. Unlike Views in Android they aren’t directly drawing anything. Widgets are rather description of the UI. This description is then inflated into actual View objects under the hood. Widgets have different lifespan they are immutable and exist until they need to be changed. Whenever widget or it’s state is changed Flutter creates a new tree of Widget instances. View in Android is only drawn once and it will redraw only when invalidate is called.
Activities and Fragments
No Activities and Fragments in Flutter. Flutter doesn’t really have a direct equivalent to activities and fragments; rather, in Flutter you navigate between screens, using a Navigator and Routes, all within the same Activity.
In Android terms, our screens would be new Activities. In iOS terms, new ViewControllers. In Flutter, screens are just Widgets!
A Route is an abstraction for a “screen” or “page” of an app, and a Navigator is a widget that manages routes. A route roughly maps to an Activity, but it does not carry the same meaning. A navigator can push and pop routes to move from screen to screen. Navigators work like a stack on which you can push() new routes you want to navigate to, and from which you can pop() routes when you want to “go back”.
In Android, you can override methods from the Activity to capture lifecycle methods for the activity itself, or register ActivityLifecycleCallbacks on the Application. In Flutter you can listen to lifecycle events by hooking into the WidgetsBinding observer and listening to the didChangeAppLifecycleState() change event.
The observable lifecycle events are:
- inactive — The application is in an inactive state and is not receiving user input. This event only works on iOS, as there is no equivalent event to map to on Android
- paused — The application is not currently visible to the user, not responding to user input, and running in the background. This is equivalent to onPause() in Android
- resumed — The application is visible and responding to user input. This is equivalent to onPostResume() in Android
- suspending — The application is suspended momentarily. This is equivalent to onStop in Android; it is not triggered on iOS as there is no equivalent event to map to on iOS
Flutter doesn’t have Intents. In Android we use Intents to navigate between Activities and communicate between components. Flutter doesn’t have Intents but you can still use them through plugins.
No more XML layout files. In Flutter you define your application layout with Widget tree.
No Adapter for ListView in Flutter. In an Android ListView, you create an adapter and pass it into the ListView, which renders each row with what your adapter returns. However, you have to make sure you recycle your rows, otherwise, you get all sorts of crazy visual glitches and memory issues.
Due to Flutter’s immutable widget pattern, you pass a List of Widgets to your ListView, and Flutter takes care of making sure that scrolling is fast and smooth.
Flutter is single threaded and runs an event loop (like Node.js), you don’t have to worry about thread management or spawning background threads. If you’re doing I/O-bound work, such as disk access or a network call, then you can safely use async/await and you’re all set. If, on the other hand, you need to do computationally intensive work that keeps the CPU busy, you want to move it to an Isolate to avoid blocking the event loop, like you would keep any sort of work out of the main thread in Android.
This is just few of Flutters features every Android developer should know when migrating to Flutter. For full list of features and examples please check Flutters documentation.
Share with your friends